x


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.

more ▼

asked Mar 10 '10 at 08:58 AM

Sun gravatar image

Sun
61 4 6 13

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Mar 10 '10 at 09:38 AM

Ricardo gravatar image

Ricardo
5.2k 20 32 96

(comments are locked)
10|3000 characters needed characters left

Use gameObject.GetComponent(nameOfScript) to store a reference to the script. Declare the variable for storing said script like so

var scriptRef : nameOfScript;

more ▼

answered Mar 10 '10 at 11:40 AM

dhendrix gravatar image

dhendrix
2.2k 25 34 59

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3420
x276
x150

asked: Mar 10 '10 at 08:58 AM

Seen: 1532 times

Last Updated: Jul 18 '11 at 11:25 AM