- Home /
How Can i Reference String another Script?
hi i got a problem. i have 2 script "a" and "b". there is code inside "a"( var x : String ; x = Unity;) and "b" has this code -> if(GUI.Button(Rect(10,10,10,10), "Click me")){ Print x;} . i need x(String) inside b Script. and they are another object........ i used to DoSomething(). but i think this fucntion not necessary this time. please tell me what i have to.
Answer by Ricardo · Mar 10, 2010 at 09:38 AM
This is a basic programming issue and not a Unity question, and similar questions have been asked before. You need only to search for reference to get a list.
Answer by dhendrix · Mar 10, 2010 at 11:40 AM
Use gameObject.GetComponent(nameOfScript) to store a reference to the script. Declare the variable for storing said script like so
var scriptRef : nameOfScript;
Your answer
Follow this Question
Related Questions
Better way of interacting and sharing variable between two scripts? 1 Answer
Need help with a raycast 1 Answer
Reference script on Behaviour is Missing, but IT'S NOT MISSING 0 Answers
Can some one help me with splash screen? 1 Answer
Getting UnassignedReferenceException even though reference assigned 1 Answer