2023-04-21 09:30:43 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Cinemachine;
|
2023-04-22 09:18:21 +02:00
|
|
|
using TMPro;
|
2023-04-21 09:30:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
public class PlayerComponent : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private float health = 5f;
|
|
|
|
[SerializeField]
|
|
|
|
private float maxHealth = 5f;
|
|
|
|
[SerializeField]
|
|
|
|
private float stamina = 20f;
|
|
|
|
[SerializeField]
|
|
|
|
private float maxStamina = 20f;
|
|
|
|
|
|
|
|
[SerializeField] private NoiseVisibilitySettingsManager noiseManager;
|
|
|
|
[SerializeField] private PlayerMovementController movementController;
|
|
|
|
|
|
|
|
public NoiseVisibilitySettingsManager NoiseManager { get { return this.noiseManager; } }
|
|
|
|
public PlayerMovementController MovementController { get { return movementController; } }
|
|
|
|
[SerializeField]
|
|
|
|
private PlayerAnimationController animationController;
|
|
|
|
|
|
|
|
[HideInInspector]
|
|
|
|
public FlareRegister flareRegister;
|
|
|
|
[SerializeField]
|
|
|
|
private CinemachineFreeLook cameraFreeLook;
|
|
|
|
private float shakeTimer = 0;
|
|
|
|
CinemachineBasicMultiChannelPerlin perlin;
|
|
|
|
[SerializeField]
|
|
|
|
private float knockbackDuration = 1f;
|
|
|
|
[SerializeField]
|
|
|
|
private float knockbackDistance = 5f;
|
2023-04-22 09:18:21 +02:00
|
|
|
[SerializeField]
|
|
|
|
private StatsOutputScreen statsOutput;
|
|
|
|
|
2023-04-21 09:30:43 +02:00
|
|
|
[HideInInspector]
|
|
|
|
public bool IsAlive { get { return this.health > 0; } }
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
flareRegister = GameObject.FindObjectOfType<FlareRegister>();
|
|
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
NoiseManager.SetRunning(MovementController.IsRunning);
|
2023-04-22 09:18:21 +02:00
|
|
|
statsOutput.health = this.health;
|
|
|
|
statsOutput.stamina = 20f;
|
|
|
|
statsOutput.oxygen = 100f;
|
2023-04-21 09:30:43 +02:00
|
|
|
|
|
|
|
if (shakeTimer > 0)
|
|
|
|
{
|
|
|
|
shakeTimer -= Time.deltaTime;
|
|
|
|
|
|
|
|
// perlin.m_AmplitudeGain = 0;
|
|
|
|
perlin.m_AmplitudeGain = Mathf.Lerp(perlin.m_AmplitudeGain, 0, .1f);
|
|
|
|
if (shakeTimer <= 0f)
|
|
|
|
{
|
|
|
|
|
|
|
|
perlin.m_AmplitudeGain = 0;
|
|
|
|
}
|
|
|
|
}
|
2023-04-22 09:18:21 +02:00
|
|
|
if (!IsAlive)
|
|
|
|
{
|
|
|
|
PlayerInteractionHandler.instance.isDead = true;
|
|
|
|
movementController.isDead = true;
|
|
|
|
}
|
2023-04-21 09:30:43 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ShakeCamera(float intensity, float time)
|
|
|
|
{
|
|
|
|
CinemachineBasicMultiChannelPerlin perlin = cameraFreeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
|
|
|
perlin.m_AmplitudeGain= intensity;
|
|
|
|
shakeTimer = time;
|
|
|
|
}
|
|
|
|
|
2023-05-12 02:14:49 +02:00
|
|
|
public void SetSensitivity(float magnitude)
|
|
|
|
{
|
|
|
|
movementController.SetSensitivity(magnitude);
|
|
|
|
}
|
|
|
|
|
2023-04-21 09:30:43 +02:00
|
|
|
public void Damage(float damage,bool applyShake=false)
|
|
|
|
{
|
|
|
|
this.health-=damage;
|
|
|
|
if (applyShake)
|
|
|
|
{
|
|
|
|
ShakeCamera(15, 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
if (other.CompareTag("Damaging"))
|
|
|
|
{
|
|
|
|
MonsterComponent monster = other.GetComponentInParent<MonsterComponent>();
|
|
|
|
|
|
|
|
this.Damage(monster.AttackDamage, monster.ShakeCameraOnHit);
|
|
|
|
animationController.Hit(this.health<=0);
|
|
|
|
this.movementController.PhysicalForceMove((transform.position - monster.transform.position)*knockbackDistance);
|
|
|
|
this.movementController.LockMovement(this.knockbackDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|