Cannot use Static var/ Unknown Idientifier

Greetings,

I’m trying to use a static var, but unity tells me it’s a Unknown Identifier. My other static var works perfectly, exception this one.

Here where’s the bug

	if(other.tag == "Player"){
	doorSpawn = goToDoorNum;
	Application.LoadLevel("L"+gameLevel+"R"+goToRoomNum);
}

gameLevel and doorSpawn are both static var declared here in another script:

//At which door does the character spawn.
static var doorSpawn : int;

//Which game level are we in.
static var gameLevel : int;

But only gameLevel return me an error. Any idea on how to force Unity to compile it correctly?

Edit:

Script A:

 //At which door does the character spawn.
static var doorSpawn : int;

//Which game level are we in.
static var gameLevel : int;

//In which room the character is.
private var charInRoom : int;

//In which room the boss is.
private var bossInRoom : int;

//How many rooms there is.
var roomsQty : int;

private var enemiesInRoom : int[];

function Awake(){
	//Resize a native array.
	enemiesInRoom = new int[roomsQty+1];
	
	DontDestroyOnLoad (transform.gameObject);
	print(enemiesInRoom.Length);
}

function Update () {
}

function charRoomUpdate(room : int){
	charInRoom = room;
}

function spawnCharacter(){
	if(gameControl.isPlaying){
		var DoorSpawn : GameObject;
		GameObject.Find("Door"+doorSpawn;)
		SendMessage.DoorSpawn(spawnCharacterDoor);
	}
}

Script B:

//The number of the door.
var doorNum : int;
gameObject.name = "Door"+doorNum;
;

//The room number to which the character will go.
var goToRoomNum : int;
//The door number the character should spawn at in the next room.
var goToDoorNum : int;


function OnTriggerEnter(other : Collider){
	if(other.tag == "Player"){
	
		doorSpawn = goToDoorNum;
		Application.LoadLevel("L"+levelManager.gameLevel+"R"+goToRoomNum);
	}
	
}

function spawnCharacterDoor(){
	SpawnPoint : GameObject;
	GameObject.Find(gameObject.name+"/Spawn");
}

You can't force Unity to compile something correctly, but it can force you to code correctly. ;-)

That a variable is static doesn't mean it can be referenced anywhere without including the name of the class in which the variable is declared - it means that only one instance of the variable exists across your project, and that you can reference it without an instance (an object) of the class in which the variable is declared.

This means that if, in ScriptA, you have written,

static var doorSpawn : int;

Then, in ScriptB, accessing the variable through "`ScriptA.doorSpawn`" is correct, but just writing `doorSpawn` is not. If your compiler doesn't give you an error with doorSpawn, it is because another local variable which is not the static one, but which has the same name AS the static one, exists in the first script.