Everything worked fine but when I compiled the game I got this error :
BCE0019: ‘MouseLook’ is not a member of ‘function(System.Type): UnityEngine.Component’.
I have seen posts about this before but it just doesn’t help the answers just say enabled doesn’t work but they don’t offer a working solution.
The Code Is Below.
var cam1 : Camera;
var cam2 : Camera;
var cam3 : Camera;
var Player : GameObject;
function Update () {
if(Input.GetKeyDown("1")){
cam1.enabled = true;
cam2.enabled = false;
cam3.enabled = false;
Player.GetComponent.MouseLook().enabled = true;
}
if(Input.GetKeyDown("2")){
cam1.enabled = false;
cam2.enabled = true;
cam3.enabled = false;
Player.GetComponent.MouseLook().enabled = false;
}
if(Input.GetKeyDown("3")){
cam3.enabled = true;
cam2.enabled = false;
cam1.enabled = false;
Player.GetComponent.MouseLook().enabled = false;
}
}
Not quite...
– Eric5h5GetComponent(MouseLook), it's a type rather than a function.Fixed it ;) btw it looks like he tried to use the generic version but the angle brackets are missing Player.GetComponent.<MouseLook>().enabled = false;
– Bunny83Thanks but i get a new error lol The name 'MouseLook' does not denote a valid type ('not found').
– DRProductionsShame on me! I copied the original line and forgot to remove the parenthesis... Thanks guys for the correction!
– aldonalettoMouseLook is a C# script, and can't be seen by JS scripts during compilation (unless already compiled in a previous "wave"). You could place the JS script in some custom Assets subfolder like Assets/JsScripts, for instance. But there's a better way to solve the problem: you can get the script by its name and cast it to MonoBehaviour - take a look at my edited answer.
– aldonaletto