Adding component to component

Hi, i am new to component object models. Here is what i want to achieve.

I have an actor component for my game objects. The actor component as a private field of type behavior. I need to be able to extend the behavior class and add it to the actor. Like this.


Do you want to switch between behaviors at runtime? Declare your behavior field like you have already. When you want to add a different behavior simply destroy the old one and add the new:

behaviour = gameObject.AddComponent(typeof(Attack));