How to create an enum-like array of classes with shared variables

First of all, let me explain, it’s really simple actually, I’m just having a massive brainfart and cannot figure out how to do this.

Basically, I want a main class, for example character which contains mutiple variables which are shared between all characters alike, such as int health, int damage, float attackSpeed, etc.

After that I want to create an actual character (e.g. Brian) and set his attributes to (x), and another one (e.g. Britney) and set her attributes to (y).

There is also a menu in which both characters are display and the player can switch between them.

Then the player controller script takes whichever character the player chose and from said declared variables it attributes them to the player, assigns a sprite and the character should switch successfully

Now, how do I create this character switcher in which all different characters inherit from a class with variables which they all share?

Help much appreciated :smile:

Moved onto How to (Or can I) edit variables from inherited class for a clearer explanation (hopefully)

Simplest approach would be to put all the character data onto a scriptable object. That way you can just make different assets for each character. Your character selector ultimately lets you select which SO is being referenced by anything else that needs to know about which character is in play, and what their stats are.

1 Like