Enable/disable Halo component in C#

“Component” class has no “enabled” variable, but somehow, in JavaScript this works:

gameObject.GetComponent("Halo").enabled = true;

How to enable/disable Halo component in C# ?

Yes, I’m not the first one asking this, but nobody has answered to this question yet…
I really would like to start using C#, not just stick with Unity’s JavaScript.

The Answer:

As Rod Green explained the structure of class inheritance, for “Halo” component, to enable/disable the “Halo” component, you need to access “Behaviour” class.

(gameObject.GetComponent("Halo") as Behaviour).enabled = true;

I’m not really sure what you are asking. However if you have a component (MonoBehaviour) of type “Halo” and wish to enable/disable it then all you need to do is.

Halo thisMono = GetComponent<Halo>();
thisMono.enabled = true;

I think however you might be getting confused about some of the class structure for the Components and MonoBehaviours in Unity.

Basically the structure goes like this:

                          ->Halo (or any other custom class you've set to inherit from MonoBehaviour)

So Halo IS a MonoBehaviour, Behaviour, Component and Object as it’s derived from those types in sequence.

What this all really means is that anything that is inherited from Behaviour has access to the .enable property