- Home /
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 :)
Thank you for your answer, I'm not quite sure on how I assign the Door variable in the Editor... may you help me out with that? :)
Thank you for answering :)
I converted your answer to a comment and i will convert one of my comment to an answer so that you can accept it to mark the question as solved.
Answer by ExTheSea · Jun 02, 2013 at 08:18 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103358im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error line 22! Help. i dont know why? 1 Answer
3 errors in scrip. 1 Answer
what is wrong with this online FPS script(not done) ? 1 Answer
Expecting ':' Found '=' Error 1 Answer