I have an ongoing loop in my Update function which is subtracting the currentStamina variable every second when the player is running.
When it has reached less than 50 it’s calling the function ExhaustedAudio.
At the moment its playing an oneshot audio, but I want to have a audio looping in there while the currentStamina is under 50 and stop looping when it’s above the 50.
It’s getting harder because the currentStamina will also increase over time when the player is not running.
Can anyone give me an example on how to handle this?
var playerExhausted : boolean = false;
Update function() {
if(currentStamina < 50) {
ExhaustedAudio();
}
}
function ExhaustedAudio() {
if(playerExhausted == false) {
Camera.main.audio.PlayOneShot(audioFile);
playerExhausted = true;
}
}