- Home /
conditional spawning
Hello all. I have a spawn script which instantiates a ball at given coordinates which works great, however I want the ball to be spawned only after a condition is met and I'm not sure how to go about doing that. Right now my script spawns the ball every 10-15 seconds with a startup time of two seconds and is repeated using invokerepeating. I want the Ball however to be spawned and repeated only after the score is equal to or greater than 50. I tried putting the invokerepeating script into an if statement in the update function but when the score was 50 a ball was spawned every frame. This must be a simple fix ...but I can't seem to figure it out, help please?
Please post your code. Edit your question, past in your code, select your code and use the 101/010 button to format it.
Answer by Entwicklerpages · Apr 16, 2014 at 03:01 PM
It is hard to help you if we don't see any code.
Generally, you should only surround the GameObject.Instantiate call with an if statement. It mustn't be the best way but it should work. Give us your code and we can help you more.
if (score >= 50)
GameObject.Instantiate(ballPrefab);
hey perfect ... thanks so much this worked 100%!! can't believe i couldn't see this...