An instance of type 'UnityEngine.Behaviour' is required

I have a script that disables my mouselook,

MouseLook = gameObject.GetComponent("MouseLook");
MouseLook.enabled=false;

and I want to add a line in another script, on the same object to re-enable mouselook.

I tried adding

MouseLook = gameObject.GetComponent("MouseLook");
MouseLook.enabled=true;

but I get

An instance of type ‘UnityEngine.Behaviour’ is required to access non static member ‘enabled’.

Where am I going wrong? I’m using an Input.GetKey to disable it on one script and an Input.GetKeyUp to enable it on the other.

Hello,

The problem is that your variable name is the same as the class name. You have a script named ‘MouseLook’, but you also have a variable named ‘MouseLook’. So naturally, Unity gets confused. It is standard convention to lowercase the first letter of variable names anyway, i.e:

mouseLook = gameObject.GetComponent("MouseLook"); 
mouseLook.enabled=false;

Good luck!

-Lincoln Green

Oh dear…

Thanks for pointing that out, I’m learning as I go and it seems so easy to overlook things like that.

Off to bugger something else up now :frowning: