- Home /
Change variable from another script - C#
I have two scripts. first script has a word variable
public string word="";
I want to to access it from another script, so i use this
GameObject wordGameObject=Selection.activeTransform.gameObject;
Word wordObject=wordGameObject.GetComponent<Word>();
Word.word = EditorGUILayout.TextField ("Text Field", Word.word);
but i get error An object reference is required to access non-static member `Word.word'
Answer by RudyTheDev · Feb 23, 2014 at 04:18 PM
You need to use wordObject.word
in your case. Word
is the class type name, wordObject
is the actual variable that holds a reference to an instance of that class.
oops. i just wrote it wrongly. i was searching whole unityAnswers for this and now realized that i had wrote Word.word :D. well, thanks
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Editing a variable from another script on collision 3 Answers
Parse String to select certain variable 1 Answer
What is "variable not assigned"? 3 Answers