- Home /
The question is answered, right answer was accepted
Remove Component
my script menu.js ; i want user prefabs in mouselook and charactermotor script remove || enabled false;
example code ; GetComponent(MouseLook).active = false; or enabled = false; not working.
how to make this ?
Thank you. Best regards.
What?!
Can you rephrase this? I have a bit of a problem deciphering this...
its simply worked check unity official
http://docs.unity3d.com/ScriptReference/Object.Destroy.html
Answer by whydoidoit · Jul 26, 2012 at 06:38 PM
To remove a component you destroy it:
Destroy( GetComponent<MouseLook>() );
But I'm not sure why your enabled = false is not working - it would imply that the script you have posted is not on the same object as the MouseLook. If it is on a parent you could use GetComponentInChildren<MouseLook>()
Thank you $$anonymous$$r. $$anonymous$$ike. And question how to add last component ? example : $$anonymous$$ouseLook or Character$$anonymous$$otor.
Thank you again :)
Oh you can add any component you like this:
var mouseLook = gameObjectOrComponent.AddComponent($$anonymous$$ouseLook);
or in a mono behaviour and you don't care about accessing it immediately:
AddComponent($$anonymous$$ouseLook);