- Home /
Pausing/Stopping the Update Function
I have a script attached to an object that is checking for certain conditions in the update loop. What I am trying to accomplish is to make this check only occur when another object is colliding with it to avoid unnecessary computation. I know I can disable the game object, but this will actually disable the whole object, not just stop the script. Is there any way to avoid this?
Answer by DaveA · Mar 18, 2013 at 10:38 PM
You can disable just that script, if that will help. Use GetComponent() and set 'enabled' on the object it gets.
If you need other parts of the script to run, you can set boolean variables in your collision routines, and check those in the Update routine. Something like:
Update()
{
if (thatThingSetInOnCollide)
{
... do that stuff...
}
}
Fantastic! I ended up setting this.enabled = false; in the start function, and this.enabled = true; in the onCollision function. Works great, thank you.
But what if I only want to disable the Update() function? I do need the other event functions (for example, on$$anonymous$$ouseDown).
If the check inside update has finished I don't need it to check 30 times every second any more.
Your answer
Follow this Question
Related Questions
Time.timeScale seems doesn't work with Update 1 Answer
Disable first person controller script, how? 4 Answers
disable touch when game is paused(Time.timeScale = 0) 1 Answer
Pause Menu Text Not Rendering 0 Answers
Disable Update function in Scripts 0 Answers