Hi everyone! I’m trying to make a pause menu in CSharp/C#. but I will not accept:
GetComponent(“MouseLook”).enabled = false;
I will ask for a reference but I don’t know how :S
Hi everyone! I’m trying to make a pause menu in CSharp/C#. but I will not accept:
GetComponent(“MouseLook”).enabled = false;
I will ask for a reference but I don’t know how :S
You have a couple of problems to work around to make this work. First, since you are using a string instead of a type, Unity does not know at compile time what kind of object you are accessing. Since it does not know it is a mouse script (or anything derived form Behaviour which is where the enabled flag comes from), it does not recognize the enabled flag.
The second problem is that you are trying to access this script from Javascript. Javascript gets compiled first, so the type MouseLook does not exist at the time this code is compiling. You can fix this problem in a couple of ways. First, if it works for you, you can write a C# script attached to the camera and do the following:
GetComponent< MouseLook >().enabled = false;
Second you can call it from Javascript like this:
GetComponent(MouseLook).enabled = false;
But if you use Javascript, then you have to move your scripts around to force the C# scripts to compile first. You can find more information here:
http://answers.unity3d.com/questions/252865/accessing-a-c-field-from-javascript.html
http://docs.unity3d.com/Documentation/ScriptReference/index.Script_compilation_28Advanced29.html