- Home /
My game freezes when I click play, is it because of my loop being infinite ?
Hello, after I included this loop, my game freezes after I click "play button" in my game. Since the "play button" is the big button on "mp3" in the game, I want to make the music play when I click "play" and the animation happen and stop, and after I click it again, music pause and animation happen again and stop. Basically I'm trying to do a non ui button.
I'm a beginner, but can somoene help me out with my code ?
Answer by tormentoarmagedoom · Jul 23, 2018 at 07:45 AM
Lol yes!
Dont use while loops, really, if you are not very used to use for and foreach, don't use whiles... you will get in problems like this..
If you think what the code does... It finish the method always as i=0 so it will never exit the while..
And a while inside a while... problems for sure!
If want something repeating, create a IEnumerator, or activate some bool variable that makes the update method execute something every frame, but dont use while for these things... really. Soemthinkg like:
bool Somethig;
void Update()
{
if (Something ==true)
{
the think to repeat each frame
}
else
{
Something=false;
}
}
void OnMOuseDown()
{
Something = true;
}
So once recieve the clik, the update method will execute a code each frame until you change that bool variable again.
Bye! :D
Okay, thank you, sorry if I came off as a complete noob with my code, but really it's because I am right now.
Your answer
Follow this Question
Related Questions
How to play an animation when a slider is at a certain value. 1 Answer
Have some minor problems. Cant tell if its a script issue or a animator issue. 1 Answer
Need Help Syncing door animations between all clients! 0 Answers
Why won't my character mesh move? 0 Answers
2D Animation does not start 1 Answer