function Update () {
if (transform.position.y < 9.125) {
underwater = true;
//we were already underwater, check for drowning
if(Time.time > lastBreath + breathTime){
//we have been underwater longer than our breath time
Drown();
}
}
function Drown () {
Drowning = true;
if(Drowning) {
Drowning = false;
SendMessage("ApplyDamage",damage,SendMessageOptions.DontRequireReceiver);
audio.PlayOneShot(drownSound);
yield WaitForSeconds(1);
Drowning = true;
}
}
This is part of a script holding all the player assets including health e.c.t it causes damage per second or at least it should. Because the Drown function is being called in the update it is calling it every frame, i want to check for underwater every frame but i want the damage and audio per second(as you can see)
.
. At the moment i get my ears pounded as the pain audio is played every frame !!
How do i fix this?