|
how do i enable and disable specific components on a gameobject with a script?
(comments are locked)
|
|
In order to be able to "disable" something, it generally must derive from Behaviour. (Renderer is a notable exception). If you see a checkbox in the Inspector, you can enable or disable it. There are a bunch of shortcuts. For those that have a checkbox, you can do it like this:
For other behaviours, like your own scripts, you can do it like this, in UnityScript:
or in C#: this isn't working. i put it in, but it comes up with 'unknown identifier. 'scriptname' ... how do i put it in?
Sep 08 '10 at 02:19 PM
Fishman92
don't worry, got it working- how can i use this in a script on another gameobject to find a component on another gameobject and enable it?
Sep 08 '10 at 02:33 PM
Fishman92
That's a different question! You really should not ask another question in a comment, but this is covered at the beginning of the manual, so have a link. http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.html
Sep 08 '10 at 10:26 PM
Jessy
(comments are locked)
|
|
My script says Assets/_Scripts/EnterExit.js(24,71): BCE0019: 'enabled' is not a member of 'UnityEngine.Component'. please help since I am only a modeler :) That's because GetComponent() returns variable of type Component. You need to cast it. Try this (substitute SphereCollider with your type of component): var mySphereCollider : SphereCollider; mySphereCollider = someObject.GetComponent("SphereCollider") as SphereCollider; SphereCollider.enabled = false; or this: someObject.GetComponent().enabled = false;
Dec 07 '12 at 11:35 AM
unfox
(comments are locked)
|
|
if you trying to diable javascript from C# you can make this (gameObject.GetComponent("FPSCounter") as MonoBehaviour).enabled = false; as when i am trying it enable didn't appear for me
(comments are locked)
|
|
Way to disable all scripts on object (C#):
(comments are locked)
|
