NullReferenceException: Object reference not set to an instance of an object
RespawnMenu.Update () (at Assets/Scripts/RespawnMenu.js:26)
heres my code:
#pragma strict
var lookAround01 : MouseLook;
var lookAround02 : MouseLook;
var charController : CharacterMotor;
var respawnTransform : Transform;
static var playerIsDead = false;
function Start ()
{
lookAround01 = gameObject.GetComponent(MouseLook);
lookAround02 = GameObject.Find("MainCamera").GetComponent(MouseLook);
charController = gameObject.GetComponent(CharacterMotor);
}
function Update ()
{
if (playerIsDead == true)
{
lookAround01.enabled = false;
lookAround02.enabled = false;
charController.enabled = false;
}
}
function OnGUI ()
{
if (playerIsDead == true)
{
if (GUI.Button(Rect(Screen.width*0.5-50, 200-20, 100, 40), "Respawn"))
{
RespawnPlayer();
}
if (GUI.Button(Rect(Screen.width*0.5-50, 240-20, 100, 40), "Menu"))
{
Debug.Log("Return to Menu");
}
}
}
function RespawnPlayer ()
{
transform.position = respawnTransform.position;
transform.rotation = respawnTransform.rotation;
gameObject.SendMessage("RespawnStats");
lookAround01.enabled = true;
lookAround02.enabled = true;
charController.enabled = true;
playerIsDead = false;
Debug.Log("Respawned Player");
}
I don’t get what the error is trying to tell me I know its saying something im referencing doesn’t exist but it does