- Home /
disable/enable Mouse Look(c#) with a script of js
I am trying to disable and enable MouseLook script, and I actually know how:
GetComponent(MouseLook).enabled = false;
//or
gameObject.GetComponent(MouseLook).enabled = false;
but, the problem is that in my script I am using JavaScript and the script MouseLook is c#. And I am not doing something wrong because I already check with another script that is JavaScript and it works, so how I can make it work with JavaScript and C#?
Answer by StephanK · Apr 20, 2011 at 07:51 PM
So what exactly is your problem? Probably it doesn't know the Type of the c# script? Then try adding the C# script to the Plugins folder.
Well, that's a problem with the build order in which scripts are compiled. Some special folders have different position within the compiling process. Sometimes it helps to place the scripts in the plugin folder to circumvent such errors. C# and JS scripts end up in seperate assemblies(DLLs). That's the reason why you can use a JS class in C# but the assembly have to be there before it can be used. It's a crosslinking problem. I would always try to use only one language ;).
Answer by Uriel_96 · Apr 20, 2011 at 09:07 PM
Oh, yeah, after checking and checking questions and answers I finally found the correct answer to my question that is here: http://answers.unity3d.com/questions/39269/disabling-a-script-mouselook I only need to do this:
GetComponent("MouseLook").enabled = !GetComponent("MouseLook").enabled;
and it works :), but thanks anyway for the other answer
Answer by Skalde · May 29, 2013 at 12:58 PM
its actually even more basic, it looks something like this:
var Player : GameObject;
var MainCamera : GameObject;
function Update () {
Player.GetComponent(MouseLook).enabled = false;
MainCamera.GetComponent(MouseLook).enabled = false;
}
No Problem ^^
Answer by rush52490 · Mar 26, 2014 at 05:26 PM
var Player : GameObject;
var MainCamera : GameObject;
function Update () {
Player.GetComponent(MouseLook).enabled = false;
MainCamera.GetComponent(MouseLook).enabled = false;
}
This code works like a charm! it save me :)
Answer by FuzzyQuills · Aug 27, 2014 at 04:26 AM
It doesn't work for me, it keeps saying: " 'enabled' is not a member of 'component' "
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
How to use "GetComponent" and "transform" code in dll file? 0 Answers
How to enable/disable Javascript using a C# script? 1 Answer
enable and disable boxcollider (whats wrong with my script?) 2 Answers