Not sure if the topic makes any sense, but basically I'm trying to instantiate a sphere(prefab) every 1 second, destroy the sphere after 2-5 seconds, and all the while have the spheres translating in x axis and speeding up faster and faster
this code is not exactly working obviously. The balls instantiate, but they don't translate. The sphere prefab has a code to destroy itself after a few seconds. My main question here is how to write a code that would speed up the balls in time. I can't write the code within the sphere prefab itself because once it destroys itself it resets the value. Any help would be great. Thanks!
asked Nov 13 '10 at 03:10 AM
To spawn the balls, you can have this script on some object in the scene, like the camera or an empty game object:
You can have a script on the ball prefab which translates it on the x axis. For the increasing speed, there are a couple of possibilities, depending on the effect you want:
If you want each ball to have its own speed, you can have a speed variable on the manager script, which you assign to a speed variable on the ball's script, using GetComponent when you instantiate the ball prefab. You would increment the speed variable after instantiating each ball.
Or you could have a static variable in the manager script, which likewise is incremented after each instantiation, and the ball's movement script would multiply its speed by the static speed variable in the manager script. That way all balls would always be going the same speed.
answered Nov 13 '10 at 04:21 AM
You already have the Speed variable; what's wrong with just doing
speed += Time.deltaTime * 0.1;
answered Nov 13 '10 at 03:59 AM