- Home /
Enabling/Disabling components disabling my GameObject?
I'm trying to do something I've done a million times, disable the MouseLook component of the main camera and the character controller on the default FPS character controller. This is how I'm trying to do it:
private Camera mainCam; private MouseLook camLook; private GameObject plyr; private MouseLook plyrLook;
void Start () {
plyr = GameObject.FindWithTag("Player");
plyrLook = plyr.GetComponent<MouseLook>();
mainCam = Camera.main;
camLook = mainCam.GetComponent<MouseLook>();
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("RotateHeld") && heldItem){
Rotating=true;
plyrLook.active=false;
camLook.active=false;
}
else if(Input.GetButtonUp("RotateHeld") && heldItem){
Rotating=false;
camLook.active=true;
plyrLook.active=true;
}
}
Its part of a simple script to let the player pick up and rotate an object. But when I say "plyrLook.active=false;" it disabled the whole GameObject associated with it for no reason I can see. The same happens with camLook... I'm at a loss...
Also, as a side note it keeps throwing a warning about me using ".active" and says that I should be using ".enabled" instead, but when I change it it says that doesent exist. This has been an on going thing, I've just ignored it but if anyone has an answer to that one too, that'd be awesome.
Answer by gegc · Aug 29, 2012 at 10:00 PM
Didn't they change that so it was "enabled" for Components and "active" for GameObjects? So if you wanted to disable a component you would do comp.enabled = false, and when you wanted to disable a whole gameobject you'd do obj.active = false. Intellisense yells at me when I do component.active.
Yeah that fixed it. Friend of $$anonymous$$e said the same thing actually! I wasn't getting any errors so I assumed they'd keep it as one command for everything, being thats the logical thing. Thanks!