- Home /
Question by
nkcowmaster · Apr 29, 2020 at 04:17 AM ·
audiotimercountdown
Play Audio at the end of a Countdown
I have a timer in my game that, when it reaches "0", triggers an "Overtime" mode. Everything related to the timer works fine... but the issue I am having is:
How do I trigger an audio effect ONCE at the end of the timer?
My audio manager is already set up, everything is good to go... the issue I am having is that everything I've attempted so far is getting affected by the fact that the timer is being controlled by the UPDATE function, so the audio is being triggered repeatedly (100 times a second).
Here's my code. I know the solution is likely bleedingly simple, I'm just not getting it!
{
public bool timerActive;
public float startingTime;
public float currentTime;
public float overTime;
public float powerupTime;
public Text matchTimerText;
// Start is called before the first frame update
void Start()
{
currentTime = startingTime;
timerActive = false;
}
// Update is called once per frame
void Update()
{
if (timerActive == true)
{
currentTime -= 1 * Time.deltaTime;
matchTimerText.text = currentTime.ToString("0");
if (currentTime <= 0)
{
currentTime = 0;
}
}
if (currentTime <= overTime)
{
OverTime();
}
if (currentTime <= powerupTime)
{
FindObjectOfType<PowerupSpawner>().PowerUpSpawn();
}
if (timerActive == false)
{
currentTime = startingTime;
matchTimerText.text = currentTime.ToString("0");
}
}
public void ActivateTimer()
{
timerActive = true;
}
public void DeactivateTimer()
{
timerActive = false;
}
public void ResetTimer()
{
currentTime = startingTime;
timerActive = false;
}
public void OverTime()
{
FindObjectOfType<OvertimeCannon>().Overtime();
matchTimerText.text = "OVERTIME";
}
}
Comment