Global variable

Hi I’m a beginner and have a problem with this:

I have a script:

static var test : int = 0;

function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
		print ("You clicked the button!");
		test = 1;
	}
}

In a other script I work with this code:

if( test == 1)
{
//...
}

The Compiler send me the mesage: Unknow identifier

I’m new in Javascript, but I don’t found something in google/forum.

Thank you for helping me!

Static doesn’t mean global, it means there is only one instance. Instead, make the variable public (which it is by default in Unityscript), and use GetComponent, as described in the docs, specifically section 3 on that page. Don’t use static unless you know what it means and actually need the variable to be static for a good reason (“I just want to access it from another script” is not a good enough reason :wink: ).

–Eric

Thank you!!! This was very helpfull!!!