- Home /
How do you use a script in another script?
I am using C# to write scripts for procedurally generated objects and my scripts are getting rather large because I am currently having to include tons of functions in the main script as I don't know how to access them from elsewhere. Using ScriptName;
doesn't work, so there's got to be some trick to it?
Answer by Xtro · Aug 07, 2013 at 05:19 PM
If the scripts are on the same object, use GetComponent() method to get it's reference.
If the scripts are on different objects, first you need to locate the object by searching its name or tag then you can use the GetComponent method.
The members of the accessed script must be public (or internal at least) to be reachable.
Ah, thanks a lot!
That helped me find more information as well: The proper time to set up these references is generally in the Awake() function.
http://unity3d.com/learn/tutorials/modules/beginner/scripting/getcomponent
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Access script (not derived from mono) functions in another script 2 Answers
how to use / simulate a using declaration in unityscript 1 Answer
MySql C# compiler error 0 Answers