Im having a problem when im looking at enemy it plays a sound and sets soundPlay to true.
But when i look away it wont set it to false. Whats wrong with my code:
if (Physics.Raycast(player.position, (transform.position - player.position).normalized, out hit) && (hit.collider.gameObject == gameObject))
{
sanity -= 1.5f;
if(soundPlay == false)
{
audio.Stop ();
audio.clip = SanityUp;
audio.Play();
soundPlay = true;
}
}
else if(sanity < 100 && soundPlay == true)
{
audio.Stop ();
audio.clip = SanityDown;
audio.Play ();
soundPlay = false;
}