Need to disable/enable C# MouseLook from jS script

The point is to disable/enable the script on the press of a button.

Here’s the script that’s supposed to disable the MouseLook:

var locked : boolean = true;


function cursorLock() {
	Screen.lockCursor = true;
	Screen.lockCursor = false;
	}





function Update() {
	if (locked == true) {
		cursorLock();
		}	
		
	if (Input.GetKeyDown("i")) {
		locked = false;
                //disable MouseLook		
                }
	if (Input.GetKeyDown("o")) {
		locked = true;
		}
	}

I’ve done some google searches and tried some of these methods:

GetComponent(MouseLook).enabled = false;

GetComponent(MouseLook).enabled = !GetComponent(MouseLook).enabled;

var mouseLook : MouseLook;
mouseLook = !mouseLook.enabled;

None of them seem to work.

Here’s the error message I get most often:
“MouseLook” is not a member of ‘function(System.Type):UnityEngine.Component’"

It may be because MouseLook is not recognized as a Component(?), but I don’t know.

Any help is appreciated!

  • Predator

You’re doing it from JavaScript. See this answer:

http://answers.unity3d.com/questions/467598/how-to-make-mouselook-in-fps-controller-stop.html?sort=oldest

Thanks for the quick response!

I did try that variant as well, and it returned this:
“enabled is not a member of UnityEngine.Component”.

try casting it:
var script:MouseLook = GetComponent(MouseLook) as MouseLook;
script.enabled =false;

Should that go in a javascript or c# script?
Not completely sure about the syntax differences yet :stuck_out_tongue:

EDIT

“The name ‘MouseLook’ does not denote a valid type (‘not found’).”

Both the script I’m working on and MouseLook.cs is located on the same gameObject.

Can you show us the whole code again? That should work in JavaScript…

If you’re referring to the first code I talked about, it’s in the first post.