- Home /
Instantiate game object on another (and follow that other).
In my game I have one game object (a sphere) that I control in order to move it on a board (its a board game).
In this objects control script, there is a var: boolean (false by default) that under certain conditions becomes true for 5 and then reverts to false.
While the bool is true (for those 5) I want to have a prefab (its an empty game object with just a collider with a certain tag) that I have in my scene, instantiated on my sphere and follow the spheres position.
I put this if statement in the spheres script:
if (boolTrue) {
Instantiate (colliderObject, transform.position);
}
The collider object has a script of its own that makes it follow the sphere and get destroyed after 5.
The problem is that I put the if statement above, inside an update function in the spheres script, the collider object gets instantiated maaaaany times (every frame I suppose).
Is there an obvious way (that I am not aware of, being a newbie) of making the collider object instantiate only once if the boolean becomes true?
I should probably use a different function to instantiate the colliderObject.
Thanks and have a happy new year!
Answer by Ejlersen · Dec 31, 2010 at 08:35 AM
You could just set the boolTrue to false after you have instantiated the object :)
O$$anonymous$$ now you made me look silly!!! LOL - thanks a bunch Ejlersen!
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
Instantiate in different position 2017.3.0f3 2 Answers
Instantiating road pieces without any spacings between 2 Answers
Keep instantiated GameObject's position while parenting it to another GameObject 3 Answers
Hi,Please i need help comparing conditions in the Update Function 1 Answer