- Home /
Problem is not reproducible or outdated
Pause menu error NullReferenceException:Object reference not set to an instance of an Object .js
why is this error coming up on js12?`enter code here
pragma strict
var pauseCanvas : Canvas;
function Start () {
Screen.lockCursor = true;
Cursor.visible = false;
}
function Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
(gameObject.Find("First Person Controller").GetComponent("MouseLook") as MonoBehaviour).enabled = false;
(gameObject.Find("Main Camera").GetComponent("MouseLook") as MonoBehaviour).enabled = false;
pauseCanvas.enabled = true;
Time.timeScale = 0;
Screen.lockCursor = false;
Cursor.visible = true;
}
}
function Resume () {
(gameObject.Find("First Person Controller").GetComponent("MouseLook") as MonoBehaviour).enabled = true;
(gameObject.Find("Main Camera").GetComponent("MouseLook") as MonoBehaviour).enabled = true;
pauseCanvas.enabled = false;
Time.timeScale= 1;
Screen.lockCursor = true;
Cursor.visible = false;
}
function ExitGame () {
Application.LoadLevel ("openingexit");
pauseCanvas.enabled = false;
Time.timeScale= 1;
}
function ExitToMain () {
Application.LoadLevel ("gui");
pauseCanvas.enabled = false;
Time.timeScale= 1;
}
Answer by hbalint1 · Apr 15, 2015 at 09:33 PM
gameObject represents the current GameObject which has the edited script on. The right method call is:
GameObject.Find("First Person Controller").GetComponent("MouseLook") as MonoBehaviour).enabled = true;
with capital 'G'.
Ok I've done this but still comes up with the error should I create a new empty again or what?
Are you sure your GameObject called like "First Person Controller" (in the hierarchy, not the component's name)? And are you sure it has a $$anonymous$$ouseLook component? I suggest you to put this line before the 12th line:
GameObject.Find("First Person Controller");
if this give you an error then your object's name is not this.
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object ? 1 Answer
NullReference Exception when adding a class 2 Answers
NullReferenceException: Object reference not set to an instance of an object 0 Answers
The infamous: Object Reference not set to an instance of an object 1 Answer
" NullReferenceException: Object reference not set to an instance of an object" 3 Answers