soundvision/UnityProject/Assets/Scripts/Math/Threshold.cs

26 lines
631 B
C#
Raw Normal View History

2019-10-07 16:53:36 +00:00
using UnityEngine;
using UnityEngine.Events;
namespace cylvester
{
public class Threshold : MonoBehaviour
{
2019-10-26 17:19:54 +00:00
[SerializeField] private float input;
2019-10-07 16:53:36 +00:00
[SerializeField] private float threshold;
[SerializeField] private UnityEvent thresholdExceeded;
private bool over_;
public void OnValueReceived(float value)
{
2019-10-26 17:19:54 +00:00
input = value;
2019-10-07 16:53:36 +00:00
if (value > threshold && !over_)
{
over_ = true;
thresholdExceeded.Invoke();
}
if (value < threshold && over_)
over_ = false;
}
}
}