Hey guys! So I’m trying to build a game with help of some tutorials. I’m currently working on a spawn system. Building it in JS and using MonoDevelop. Once I try to enter playmode i get an error saying: NullReferenceException: Object reference not set to an instance of an object RespawnMenu2.Start() (at Asset/Scripts/RespawnMenu2.js:14).
Note: I have added the mouse control (C#) as a component attached to the camera.
Scipt: (JS)
#pragma strict
var lookAround01 : MouseLook;
var lookAround02 : MouseLook;
var charMotor : CharacterMotor;
var respawnTransform : Transform;
static var playerIsDead = false;
function Start ()
{
lookAround01 = gameObject.GetComponent(MouseLook);
lookAround02 = gameObject.Find(“MainCamera”).GetComponent(MouseLook) // This is the error line
charMotor = gameObject.GetComponent(CharacterMotor);
}
function Update ()
{
if (playerIsDead == true)
{
lookAround01.enabled = false;
lookAround02.enabled = false;
charMotor.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 , 100, 40), “Menu”))
{
Debug.Log(“Return to Menu”);
}
}
}
function RespawnPlayer ()
{
transform.position = respawnTransform.position;
transform.rotation = respawnTransform.rotation;
gameObject.SendMessage(“RespawnStats”);
lookAround01.enabled = false;
lookAround02.enabled = false;
charMotor.enabled = false;
playerIsDead = false;
Debug.Log (“Player has respawned”);
}
Have you guys got any idea about what I’m doing wrong? Glad for any help.
Link for Youtube-tutorial: http://www.youtube.com/watch?v=pZGvn458Xx0&list=PLPV2KyIb3jR7F_B4p8X3YwHPaExh0R9Kk&index=24