- Home /
Toggling a game object between an active and inactive state
I have an application I'm developing for iOS. When an object is touched, it disappears, adds points to a score, and then respawns in a new location after 5 seconds. I'm having trouble with the object respawning, but the essential problem is in the abbreviated script I wrote below. Why doesn't this code re-activate the game object and what's the best way to toggle between active and inactive for iOS?
function Start () {
gameObject.active = false;
yield WaitForSeconds(5.0); // wait for 5 seconds
gameObject.active = true;
yield WaitForSeconds(5.0); // wait for 5 seconds
gameObject.active = false;
yield WaitForSeconds(5.0); // wait for 5 seconds
gameObject.active = true;
}
I don't believe you can use yield WaitForSeconds() in Start() ... or is that just Update()?
Could someone verify this?
Answer by DaveA · Apr 07, 2012 at 07:19 AM
I believe what is happening is that when you deactivate 'this' gameObject, it stops processing scripts at all. So you can instead deactivate the renderer on this this object, or put the script on another object that references this object.
Your answer
Follow this Question
Related Questions
How to find Inactive GameObject 16 Answers
GameObject.Find() work on inactive objects 16 Answers
Activate gameobject that is deactivated with c# 2 Answers
Help Activating/Deactivating all Game Objects with same tag 1 Answer
Finding all GameObjects with the same tag when some of them are inactive? 4 Answers