Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Reference Exception in Unity game engine
    text
    copied!<p>I am trying to go through a tutorial on Unity (Will Goldstone's book 3.x Game Development Essentials) and keep running into an error messages and I just can't figure out what is wrong with my code. It's from Chapter 5, I am writing this in Javascript. For what i can see I have everything correct--the null reference comes up in my OpenDoor function line 2 &amp; in my shutDoor function line2.:</p> <blockquote> <p>Null Reference Exception PlayerCollisionsjs.OpenDoor(UnityEngine.GameObject door) (at Assests/Scripts /PlayerCollisionsjs.js: 47 **and 37 the lines refecenced below).</p> </blockquote> <p>What am I missing? My <code>OpenDoor</code> &amp; <code>CloseDoor</code> sounds are loaded and the code works if I remove the shut Door requests...any thought </p> <pre><code>#pragma strict private var doorIsOpen : boolean = false; private var doorTimer : float = 0.0; private var currentDoor : GameObject; var doorOpenTime : float = 3.0; var doorOpenSound : AudioClip; var doorShutSound : AudioClip; function Start () { } function Update () { if(doorIsOpen) { doorTimer += Time.deltaTime; if(doorTimer &gt; doorOpenTime) { shutDoor(currentDoor); doorTimer = 0.0f; } } } function OnControllerColliderHit(hit : ControllerColliderHit){ if(hit.gameObject.tag == "playerDoor" &amp;&amp; doorIsOpen == false) { currentDoor == hit.gameObject; OpenDoor(hit.gameObject); OpenDoor(currentDoor); } } function OpenDoor(door: GameObject) { doorIsOpen = true; door.audio.PlayOneShot(doorOpenSound); door.transform.parent.animation.Play("dooropen"); } function shutDoor(door : GameObject) { doorIsOpen = false; door.audio.PlayOneShot(doorShutSound); door.transform.parent.animation.Play("doorshut"); } </code></pre> <p>I did see that someone else got stuck on the same code, but we don't have the same problem, my audio works before I insert the shutDoor function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload