Clones of Prefabs problem

Hello everyone, In some specific time periods, I want to speed up the steam of my prefabs which goes from left side of the screen to the righ side. And ı’m applying a force with the “Rigidbody.addforce” But ı want to apply this speeding up both to the prefabs which has already been produced and to the new ones which will be produced. Otherwise its being a syncronisation problem in the screen. Do you guys know how can ı do this?

Why not to store current force and then asign it on instantiating.

You could use a static speed variable in their script, then just increase the value and all gameObjects using the script will be able to use the value in their Update() methods.

how can i change speed of prefabs previously created

If you store a list or arraylist of all active objects then you can just loop through them adjusting their speed.

1 Like

Yep. You could likely use a listener for changes in speed as well. Not sure which is faster.

1 Like

.Does prefabs automaticlly removed from arraylist when destroyed. Or can i scripting manuelly for this?

and is there anyway to reach all clones which were already created without using arraylist?

OK once you have instantiated a prefab it’s a gameObject. You can use a script on the gameObject that uses the OnDestory() method to remove it from the arraylist.

If the cloned gameObjects all have the same script on them then you can use the static speed variable I mentioned before.

1 Like

thank you too much for your answers, i understood which way i must follow. But i really hate to use arraylist. So is there anyway to reach all clones which were already created without using arraylist?

You can do a GameObject.Find or have them subscribe to an event listener thing.

1 Like

i have no idea how event listenig is working? and i didnt find this from scripting reference :confused:

GameObject.Find (probably find by tag?) is likely the easiest.

1 Like