- Home /
Why is my update function acting wierd?
Hi! I upgraded to Unity 4.2 and suddenly I had a problem with the Update function. I made a function GoAndRun() and in it has conditions for making gameobjects disabled/enabled. When the Update function runs the GoAndPlay(), it keeps on running it even though the If conditions are false. Here are pictures.
Answer by oliver-jones · Sep 16, 2013 at 09:25 PM
Thats because the GoAndRun() is being called everyframe by your Update, and you can't have a WaitForSeconds() within an Update.
You're almost there though -you need to make a boolean trigger to prevent it being called every frame:
function GoAndRun(){
if(part1 == true && part1Wait == false){
part1Wait = true;
yield WaitForSeconds(3);
part1 = false;
part2 = true;
//etc ...
Also, it's helpful if you actually paste your code into the question as I can then C/P it and edit it, instead of having to keep scrolling up and viewing the code. Anyway - try something like that (do it with your part2 as well), also you will need to reset them after, else it will only be called once.
FYI - this problem you're having has nothing to do with the version - this will happen no matter what
Your answer
![](https://koobas.hobune.stream/wayback/20220613114311im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to export MMD model to Unity? 0 Answers
A node in a childnode? 1 Answer
How to expose variables in c# according to selected booleans 1 Answer