- Home /
The question is answered, right answer was accepted
Access Another Script (Unity 5)
I can't find how to access a variable from another script in the Unity 5. I know the changed some things but i just can't get it right. In the old Unity i used var TheScript : Script;
and then to call it TheScript.AVarFromTheScript = false;
. That doesn't seem to work anymore. I get the error unknown identifier. I also checked this page out but i can't get it working.
Answer by Statement · Oct 09, 2015 at 10:34 PM
Seems to work just fine.
ScriptA.js:
#pragma strict
var otherScript : ScriptB;
print(otherScript.someVariable);
ScriptB.js:
#pragma strict
var someVariable : String = "Hello World!";
Do you perhaps have other errors in your project? Check the console for hints. Typos? Are you sure you got the variable name correct?
I'm such an idiot. $$anonymous$$y script was named "$$anonymous$$enu" and i guess i couldn't use that name to access it. I tested it with a different name and it works fine. Sorry about that and thanks.
Follow this Question
Related Questions
Can't access script through collision. 2 Answers
How do I access the contents of a script from another script? 2 Answers
A Javascript trying to access an image effect C# script 1 Answer
How do I access a script from a class inside a script. 1 Answer
Having trouble accessing a unique instance of a dynamically generated script... 0 Answers