I've searched for a while now, and it seems that I am still getting this null reference after a bit of debugging. Code (JavaScript): #pragma strict var doorClip : AnimationClip; var Key : GameObject; var SledgehammerHit : AudioClip; var LockedDoorSound : AudioClip; var isDoorOpen = false; private var BakeryDoorState = false; private var BakeryDoor : Sledgehammer; function Start() { BakeryDoor = GameObject.Find("Sledgehammer").GetComponent(Sledgehammer); } function Update () { if (Input.GetKeyDown(KeyCode.E) && BakeryDoorState == true && BakeryDoor.KeyCollected == true && isDoorOpen == false) { GameObject.Find("BakeryDoors").GetComponent.<Animation>().Play("bakeryDoorsFalling"); AudioSource.PlayClipAtPoint(SledgehammerHit, transform.position); isDoorOpen = true; } else if (Input.GetKeyDown(KeyCode.E) && BakeryDoorState == true && BakeryDoor.KeyCollected == false) { AudioSource.PlayClipAtPoint(LockedDoorSound, transform.position); } } function OnTriggerEnter (theCollider : Collider) { if (theCollider.tag == "Player") { BakeryDoorState = true; } } function OnTriggerExit (theCollider : Collider) { if (theCollider.tag == "Player") { BakeryDoorState = false; } } For reference, I have 2 objects called Sledgehammer and BakeryDoors. The doors have the door script, and audio source, a trigger, and an Animation with an anim attached called bakeryDoorsFalling. The animation is set to Legacy. It only occurs when I push E on the door with the hammer collected, so it has to be in the 'if' somewhere, Can anyone tell me why it's occuring?
@LeftyRighty Perhaps the one that is stated in the title, I'm not sure though. @GamesOnAcid I assume it's caused in line 19 (due to the thread title, if not, provide more information). Check whether Code (JavaScript): BakeryDoor = GameObject.Find("Sledgehammer").GetComponent(Sledgehammer); returns null or finds an object. Put a Debug.Log statement and compare it to null. If it's not the one causing the issue, continue just like that.
Yes, when I check it, it returns null immediately on start. I do have a GameObject called Sledgehammer, and a script with the same name on it. Here is the code for it if necessary. Code (JavaScript): #pragma strict var TheKey : GameObject; var buttonInRange; var buttonActivated; var KeyCollected = false; public var guiSkin : GUISkin; private var hasPlayed = false; function OnTriggerEnter (theCollider : Collider) { if (theCollider.tag == "Player") { buttonInRange = true; } } function OnTriggerExit (theCollider : Collider) { if (theCollider.tag == "Player") { buttonInRange = false; } } function OnGUI() { if(buttonInRange == true) { GUI.skin = guiSkin; GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 200, 100), "Pick Up Sledgehammer"); } } function Update() { if(buttonInRange == true) { if(Input.GetKeyDown ("e")) { if(!hasPlayed) { hasPlayed = true; KeyCollected = true; Destroy(TheKey); } } } }