StationObscurum/Assets/Scripts/Player/NoiseVisibilitySettingsManager.cs

62 lines
1.5 KiB
C#
Raw Normal View History

2023-04-21 09:30:43 +02:00
using UnityEngine;
public class NoiseVisibilitySettingsManager : MonoBehaviour
{
2023-06-01 17:03:48 +02:00
[SerializeField] private float sneakNoiseDistance = 5f;
[SerializeField] private float runNoiseDistance = 10f;
[SerializeField] private float shootNoiseDistance = 30f;
[SerializeField] private float standNoiseDistance;
[SerializeField] private float shootNoiseDuration = 2f;
private bool isRunning;
private bool isSneaking;
private float timeSinceLastShot;
public float SneakNoiseDistance => sneakNoiseDistance;
public float RunNoiseDistance => runNoiseDistance;
public float ShootNoiseDistance => shootNoiseDistance;
public float StandNoiseDistance => standNoiseDistance;
public float NoiseDistance { get; private set; }
2023-04-21 09:30:43 +02:00
// Start is called before the first frame update
2023-06-01 17:03:48 +02:00
private void Start()
2023-04-21 09:30:43 +02:00
{
}
// Update is called once per frame
2023-06-01 17:03:48 +02:00
private void Update()
2023-04-21 09:30:43 +02:00
{
2023-06-01 17:03:48 +02:00
if (timeSinceLastShot > 0)
NoiseDistance = shootNoiseDistance;
2023-04-21 09:30:43 +02:00
else if (isRunning)
2023-06-01 17:03:48 +02:00
NoiseDistance = runNoiseDistance;
else if (isSneaking)
NoiseDistance = sneakNoiseDistance;
2023-04-21 09:30:43 +02:00
else
2023-06-01 17:03:48 +02:00
NoiseDistance = standNoiseDistance;
2023-04-21 09:30:43 +02:00
timeSinceLastShot -= Time.deltaTime;
}
public void ShotFired()
{
2023-06-01 17:03:48 +02:00
timeSinceLastShot = shootNoiseDuration;
2023-04-21 09:30:43 +02:00
}
2023-06-01 17:03:48 +02:00
2023-04-21 09:30:43 +02:00
public void SetRunning(bool isRunning)
{
this.isRunning = isRunning;
}
2023-06-01 17:03:48 +02:00
2023-04-21 09:30:43 +02:00
public void SetSneaking(bool isSneaking)
{
2023-06-01 17:03:48 +02:00
this.isSneaking = isSneaking;
2023-04-21 09:30:43 +02:00
}
2023-06-01 17:03:48 +02:00
}