This was raised in the comments of another question but it was suggested I make it a standalone question.
Unity is my first proper taste of Javascript so i'm still a bit rusty on the fundamentals. Before Unity I used Director MX 2004 so I understand the difference between private and global variables. In Unity, i've been using member, private and global variables as defined by the scripting docs with no problems. Bear with me while I outline the differences for others (as quoted in the docs):
member variables
Any variable defined outside of any function defines a member variable. The variables are accessible through the inspector inside Unity. Any value stored in a member variable is also automatically saved with the project.
var memberVariable : int = 0.0;
private variables
Private member variables are useful for storing state that should not be visible outside the script. Private member variables are not saved to disk and are not editable in the inspector.
private var myHiddenVariable : int = 0.0;
global variables
You can also create global variables using the static keyword.
static var someGlobal = 5;
To access it from another script you need to use the name of the script followed by a dot and the global variable name.
TheScriptName.someGlobal = 10;
However, i've recently started coming across the public keyword but little mention of it except in the Unify list of keywords, but the description doesn't really help me since I suspect I still have much to learn about JS itself, never mind UnityScript.
Since this seems like a useful bit of info for anyone, could someone please explain the difference between using
public var myVariable : int = 0.0;
and
var myVariable : int = 0.0;
to expose a variable?
Many thanks.