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#?
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.
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
Skalde
May 29, 2013, 12:58pm
4
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 ^^
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
It doesn’t work for me, it keeps saying: " ‘enabled’ is not a member of ‘component’ "
Here is the problem I been having where I get
“Assets/Scripts/Inventory.js(26,53): BCE0005: Unknown identifier: ‘MouseLook’.”
Here is the script in Js. I have tried several options and stumped.
if(showGUI == true)
{
Time.timeScale = 0;
GameObject.Find(“First Person Controller”).GetComponent(FPSInputController).enabled = false;
GameObject.Find(“First Person Controller”).GetComponent(MouseLook).enabled = false;
GameObject.Find(“Main Camera”).GetComponent(MouseLook).enabled = false;
GameObject.Find(“FPSArms_Axe@Idle”).GetComponent(PlayerControl).enabled = false;
GameObject.Find(“Main Camera”).GetComponent(RayCastCollect).enabled = false;
}
if(showGUI == false)
{
Time.timeScale = 1;
GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = true;
GameObject.Find("First Person Controller").GetComponent(MouseLook).enabled = true;
GameObject.Find("Main Camera").GetComponent(MouseLook).enabled = true;
GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerControl).enabled = true;
GameObject.Find("Main Camera").GetComponent(RayCastCollect).enabled = true;
}
}
Anyone else have an answer?
This code Helped My Friend!
var Player : GameObject;
var MainCamera : GameObject;
function Update () {
Player.GetComponent(MouseLook).enabled = false;
MainCamera.GetComponent(MouseLook).enabled = false;
}