I am trying to figure out why I get the errorNullReferenceException: Object reference not set to an instance of an object
I am trying to read a var from another script, like this.
ScriptA
var : someText : String;
And the second script
scriptB
var someString : String;
var Text : ScriptA;
function OnAwake()
{
Text = GetComponent(ScriptA);
}
someOtherFunction()
{
someString = Text.someText;
}
I have looked all over for a solid answer to this, as I know its probably not that hard.
Thank you!
-RhoneRanger
You want ‘Awake’ or ‘Start’. ‘OnAwake’ will not be called. Just FYI, what you are doing above will only work if both scripts are attached to the same game object. If they are on different objects, you’ll have to get a reference to the object first then you can do something like:
text = goFound.GetComponent(ScriptA);
Also, variables should be named starting with a lower case letter.