using UnityEngine;

public abstract class ReactOnNoise : MonoBehaviour
{
	public float tolerance;
	
	public abstract void tooMuchNoise();
	
	protected float noise = 0f;
	
	void Awake()
	{
		Wave.waveFired += noiseMade;
	}
	
	void OnDestroy()
	{
		Wave.waveFired -= noiseMade;
	}
	
	void FixedUpdate()
	{
		if(noise > tolerance)
			tooMuchNoise();
		if(noise > 0)
			noise -= 0.01f;
		else
			noise = 0;
	}
	
	private void noiseMade(object sender, Wave.WaveEventArgs e)
	{
		noise += e.strength * (0.7f/((transform.position - e.pos).magnitude + 1));
	}
}