So I have some code that was working in Unity 4.5x and I recently moved to Unity 5 the error I am getting is NullReferenceException: Object reference not set to an instance of an object Menu.Update () (at Assets/Scripts/Player/Menu.cs:33).
I am unsure what I am doing wrong or how the API changed that is preventing me from unlocking the mouse and locking mouse look like I used to is there a new way to do this? Do I need to remove the first person controller or something?
I have the following code:
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour
{
bool inMenu;
public Canvas InGameMenu;
public Canvas Options;
// Use this for initialization
void Start ()
{
inMenu = false;
Screen.lockCursor = true;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyUp(KeyCode.Escape))
{
if(InGameMenu.enabled || Options.enabled)
{
Screen.lockCursor = true;
GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = true;
GameObject.Find("Main Camera").GetComponent<MouseLook>().enabled = true;
InGameMenu.enabled = false;
Options.enabled = false;
}else
{
InGameMenu.enabled = true;
GameObject.Find("Main Camera").GetComponent<MouseLook>().enabled = false; //line 33 error here
GameObject.Find("First Person Controller").GetComponent<MouseLook>().enabled = false;
Screen.lockCursor = false;
}
}
}
}