Question by
MachoBrizzin · Nov 15, 2015 at 05:08 AM ·
c#timeraudioclip
Play Audio with Timers
So I have a countdown which is decreasing from 5.0f with time.deltaTime. After each second, I want to play an AudioClip. For example, when the timer hits 3, play a clip. Then when it hits 2, play another one. Same all the way until 0.
Problem is, the audio is being mixed together or something. and its really scratchy.
Here's the code.
public IEnumerator StartGame()
{
//Countdown from startGameCountdown.
GameSettings.startGameCountdown -= Time.deltaTime;
GameSettings.countdownText.text = "" + GameSettings.startGameCountdown.ToString("0");
if(GameSettings.startGameCountdown == 3)
{
GameSettings.timerSource.PlayOneShot(GameSettings.timerBeep);
}
else if (GameSettings.startGameCountdown == 2)
{
GameSettings.timerSource.PlayOneShot(GameSettings.timerBeep);
}
else if (GameSettings.startGameCountdown == 1)
{
GameSettings.timerSource.PlayOneShot(GameSettings.timerBeep);
}
else if(GameSettings.startGameCountdown == 0)
{
GameSettings.timerSource.PlayOneShot(GameSettings.finalBeep);
}
yield return null;
}
Comment
Your answer
Follow this Question
Related Questions
Perform action If Input is done in this time. 2 Answers
How do I stop my timer by accessing a variable from another script? 2 Answers
Editable Timer 0 Answers
How can I make this clip play once 1 Answer