x


How to disable/enable Halo component via script

Is it possible to control the Halo component similar to the other components? Something like:

renderer.enabled = false;
collider.enabled = false;

GetComponent("Halo").enabled = false; did not work for me aswell ( 'enabled' is not a member of 'UnityEngine.Component'. )

more ▼

asked Oct 01 '11 at 09:10 PM

Eddy Johnson gravatar image

Eddy Johnson
18 5 5 10

If you're using C#, you need to do "GetComponent().enabled = false;" instead. The one Save referenced you to is a JavaScript-only implementation and the syntax won't be correct for C#.

Oct 01 '11 at 11:49 PM Jason B
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The Halo component isn't connected to the renderer class. You'd have to do this:

GetComponent("Halo").enabled = false;

If it doesn't work, where are you calling it from and how? Just tested on the GameObject and it works well.

more ▼

answered Oct 01 '11 at 09:16 PM

save gravatar image

save
8.2k 22 31 62

I am calling it in a script attached to a prefab, which will be instantated during gameplay. Prefab also has a collider used as a trigger and a Halo component. I need to disable some components once something hits the trigger collider:

function OnTriggerExit(other : Collider) { Destroy(other.gameObject);

GetComponent("Halo").enabled=false;
renderer.enabled = false;
collider.enabled = false;   

}

But I get "BCE0019: 'enabled' is not a member of UnityEngine.Component'. " on line GetComponent("Halo").enabled=false;

PS Sorry I am using a different acount, but I could not log in anymore...

Oct 02 '11 at 02:52 PM eddyjohnson3

This technique does not compile for iOS

Mar 19 '12 at 09:58 PM AaronC

I find it's better to pass a type argument to GetComponent().

GetComponent("Halo") returns a Component reference.

GetComponent(Halo) returns a Halo reference.

The difference is crucial if you're using static typing.

Mar 20 '12 at 06:57 AM rutter
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x302
x66
x33

asked: Oct 01 '11 at 09:10 PM

Seen: 2853 times

Last Updated: Mar 20 '12 at 06:57 AM