Can some one help me out with static variables. I understood them at first and was success in using them. However in a new script I’m developing I’m using a global variable defined in another script in another folder, same language (JavaScript/Unity Script). I’ve been unsuccessful in accessing this variable leading me to receive an error saying “Unknown identifier”
1 Answer
1well, let’s say your script is called “ScriptA” and contains this declaration:
static var myGlobalVar : int;
you can access this var from any other script, by saying:
ScriptA.myGlobalVar = 10;
simple as that
That's what I have down in my script. So separation of folder isn't an issue?
– DoctorToddI suppose it could be, IF you are using one of Unity's pre-defined "special" folders: http://answers.unity3d.com/questions/18981/what-are-all-the-special-folders-and-what-do-they.html (due to the compilation order) http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html
– Seth-BergmanThanks that may be why my scripts can't find them, I'll try moving them around.
– DoctorTodd