This is my code. MouseLook is the class that I want to set Enabled from, Enabled is a bool.
if (Input.GetKeyDown (KeyCode.Escape)) {
Paused = !Paused;
if (Paused) {
MouseLook.Enabled = false;
Time.timeScale = 1;
NGUITools.SetActive (PauseMenu, false);
}
if (!Paused) {
MouseLook.Enabled = true;
Time.timeScale = 0;
NGUITools.SetActive (PauseMenu, true);
}
}
Create an reference or a object reference for the MouseLook. It seems that you don’t have this reference, try this:
//set the reference on the inspector
GameObject objectReference;
MouseLook mouse = objectReference.GetComponent<MouseLook>();
mouse.enabled = false;
Make sure the MouseLook script is being compiled before you reference it. To do this, you could edit the script priorities in the Editor, or for simplicity, place it in a folder in Assets, such as Plugins with the script you are accessing it from in the root Assets folder.
Once that is done, you can either set a public GameObject variable to take the reference from, or run a Find on the name or tag of the MouseLook GameObject. This will give you a reference to the main object, which we will call mouseObject.
After you have a reference to the GameObject, use:
MouseLook mouseLook = mouseObject.GetComponent<MouseLook>();
mouseLook.enabled = true;
It the object you are referencing from is the primary camera (has the MainCamera tag) then you can skip over the GameObject location and use Camera.main instead of mouseObject.