List of classes c#

Hey Unity Community :slight_smile:

I’m currently Implementing a class (wizard, thief, warrior) system for my rpg. I want to add all of my abilities to a list so that I can refer to them numerically because each class will have different abilities and I want to do some math with them for the purpose of the GUI. Here are some examples of my abilities (they’re all at the bottom of the class(wizard, thief, warrior) script:

public class Wizard : Character 
{
	//wizardy traits
}

public class Fireball : Ability
{
	// do fireball stuff
}

public class FrostArmour : Ability
{
	// do frosty armoury stuff
}

The GUI is being handled by a separate script (SelectionManager.cs). anyway simple question how do I add each Ability class to a list for easy reference?

I’d suggest to declare abilities list for each character (as @TheNinjassin correctly mentioned in the comments):

public class Wizard : Character
{
	public Ability[] abilities;
}

Please note I use regular array instead of generic List as suggested by other guys. Regular arrays are resources-wiser to use in your case, since you’re not going to dynamically resize arrays with abilities at runtime (and you’re still free to use Array.Resize() even if you’re going to do so).

You can implement an interface and make a list from that. Something like the following:

public Interface IAbility {
    //Implement all your common functionality here.
}

public class Wizard : Character, IAbility {}
public class FireBall: Ability, IAbility {}

// This list will take both components
private List<IAbility>;