Hi
I have a prefab of which a number of instances are created at runtime. The prefab has a script attached which makes reference to a variable in another script. (Basically I am creating some people which move according to their attached script, but their speed is set by a global speed variable used by all objects in the scene).
Is there an easy way to set this variable at runtime? If the prefab instance was present at all times then I would just drag the relevant object (containing the speed script) onto the the prefab instance, but of course you cannot do this at runtime.
Thanks very much in advance!
EDIT: So essentially what I need to do is the equivalent of waiting for the prefab instance to be created, pausing the game, dragging the object containing the global speed variable onto the instance of the prefab, then starting the game again. If anyone knows how to do this in code it would be very useful (apologies; I’m new to Unity).
Xtro
2
Hmm, the key point of this question is that if the “prefab links” is working in the play mode or not.
As far as I know, No… In play mode, there is no gameobject<->prefab link. When you instantiate a prefab, the instantiated one is totally an independent object. So they don’t share variables on them.
If I’m correct, You can only search for all the object which has your script on them (or maybe a tag search), then apply the change you want to make in a loop.
If I’m wrong about prefab links in play mode, please someone correct me.