Need Help | Door Opening Script Error

Hallo,

I’m new to unity, and this morning I tried to make a door opening by a user input. And I got an error, hope someone can help me out.

This is the error:

UnassignedReferenceException: The variable Door of ‘DoorLogic’ has not been assigned. You probably need to assign the Door variable of the DoorLogic script in the inspector. DoorLogic+$changeDoorState$1+$.MoveNext () (at Assets/DoorLogic.js:43) UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator) DoorLogic:Update() (at Assets/DoorLogic.js:11)

Here is the code I use:

#pragma strict

var Door: Transform;
private var drawGUI = false;
private var doorIsClosed = true;

function Update () 
{
	if (drawGUI == true && Input.GetKeyDown(KeyCode.E))
	{ 
		changeDoorState();
	}
}

function OnTriggerEnter (theCollider : Collider)
{
	if (theCollider.tag == "Player")
	{
		drawGUI = true;
	}
}

function OnTriggerExit (theCollider : Collider)
{
	if (theCollider.tag == "Player")
	{
		drawGUI = false;
	}
}

function OnGUI ()
{
	if (drawGUI == true)
	{
		GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Press E to open");
	}
}

function changeDoorState ()
{
	if (doorIsClosed == true)
	{
		Door.animation.CrossFade("Open");
		//Door.audio.PlayOneShot();
		doorIsClosed = false;
		yield WaitForSeconds(3);
		Door.animation.CrossFade("Close");
		//Door.audio.Play();
		doorIsClosed = true;
	}
}

Thanks for looking into my problem, looking forward to solve it :slight_smile:

If the script is actually attache to the Door then you can replace

Door.

with

transform.

If that’s not the case: If you attach a script all the variables show up in the inspector below the name. then you just drag the gameobject on the Door variable.