- Home /
Accessing Variables (again)
How would I go about accessing variables in another script? I tried this:
var Resources : OtherScript;
But Unity gave me this error:
The name OtherScript does not denote a valid type
Why? It seems perfectly valid to me! Any help appreciated, because I'm totally stuck with a script that should work, that's not working. Thanks in advance...
Elliot Bonneville
EDIT: OtherScript
won't show up in the inspector, and I got this script from the docs.
Answer by Eric5h5 · Mar 23, 2010 at 02:18 AM
"OtherScript" is the name of your other script. You don't literally type OtherScript unless your other script is actually and for real called OtherScript.js. Otherwise you use the script name. It will show up in the inspector once you fix any errors you have.
Answer by straydogstrut · Mar 23, 2010 at 02:12 AM
From the Unity Scripting Reference:
Global variables
You can also create global variables using the static keyword.
This creates a global variable called someGlobal.
// The static variable in a script named 'TheScriptName.js' static var someGlobal = 5;
// You can access it from inside the script like normal variables: print(someGlobal); someGlobal = 1;
To access it from another script you need to use the name of the script followed by a dot and the global variable name.
print(TheScriptName.someGlobal);
TheScriptName.someGlobal = 10;