- Home /
Call instantiated object from other script.
This is a very basic question.
Normally if I wanted to manipulate a non instantiated object (something initially in the heirarchy on startup) from a script, I'd have to attach it to that script by first declaring a variable, then dragging it across to the script in the IDE.
I can't do that with instantiated objects obviously so how can I go about referencing them from other scripts?
Answer by AlucardJay · Sep 04, 2012 at 04:56 PM
use GameObject.Find : http://docs.unity3d.com/Documentation/ScriptReference/GameObject.Find.html
This searches by name. You can also search by tag :
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindWithTag.html
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html
Or a different method would be when you instantiate the object, assign that object to a variable on the other script. (otherScript.someVar = thisScriptCloneObj;)