List of scripts?


Instead of having multiple scripts as components for an object, is it possible to have a master script component that can hold a list of other scripts, or an array of scripts?

You could store a string array of Class names. It wouldn’t give you the drag and drop functionality, or the strict type validation, but it would allow you to add components on demand. Define the array:

public String[] AbilityTypeNames;

You could then do something like this at runtime:

Type abilityType = Type.GetType(AbilityTypeNames*);*

Ability newAbility = (Ability)gameObject.AddComponent(abilityType);
That would allow you to define the ability classes without instances and spawn the instances as needed at runtime.

Yeah. To do so, Double Jump and Dash should inherit from Ability. With every script inheriting from Ability, you can create a list of Abilities.

class Ability : MonoBehaviour

class Dash : Ability