- Home /
Access prefab's variables after instantiation
I have looked at similar questions: http://answers.unity3d.com/questions/33433/Cant-access-prefabs-variables-once-instantiated.html and http://forum.unity3d.com/threads/134864-accessing-an-instantiated-prefab-s-variables but they do not solve my problem.
Say, I have a prefab called MovingSoldier
and I instantiate it as follows:
GameObject ms=(GameObject) Instantiate(MovingSoldier,new Vector3(10,32,91),transform.rotation);
MovingSoldier
has a C# script attached called SoldierScript
and the script has a variable speed
. How do I access and change the variable speed
from the object ms
I created above?
Answer by MountDoomTeam · Apr 30, 2013 at 11:37 AM
you can try sendmessage http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SendMessage.html it's okay to send information every few frames and if you need something faster, you need to write the code in your script that gets the variable change signal from the other script it depends on, and look for questions called how to access variable from other script