Unity countdown timer music

C#Fobia

New member
Joined
Jan 19, 2022
Messages
1
Programming Experience
Beginner
Hi People Im a total newbie and having a small problem on a script in Visual Studio using Unity. Where do i post my question?

The Question: I have a countdown timer on my small game, when it reaches 10 secs a new interactive music should start. It does with this code:
C#:
if (secondsLeft == 10)
        {
            CountdownMusic.Post(gameObject);
        }
But when it starts it runs multiple time till reaching an absolute mess...

I need to create a bool but not sure exactly how to do this to stop the music getting played several time at once...

Thanks
Harry
 
Last edited by a moderator:
Currently, we don't have a Unity specific subforum.

Anyway, recall that the update code in Unity can be called multiple times per second. So that condition will be true multiple times.

You seemed to have successfully created a variable named secondsLeft. You would create a similar variable but of type bool instead of int.
 
Back
Top Bottom