many "characters" data

I’m making a game that will have many different characters that all have the same variables: move, range, attack, defense, maxHealth. Once created, none of these variables will change.
For instance one will have

byte move = 3;
byte range = 2;
byte attack = 2;
byte defense = 5;
byte maxHealth = 5;

My question is what’s the best way to go about storing this data? Should I make a class for each character and pull it from there? Or just put the data into the variables as they are instantiated through direct code (which is how I’m doing it atm), or some other way?

Great question

Definitely use classes, if the characters are different types use an abstract base class. The absolute best way is to use a database of course, next best would be a less permanent form of storage like xml, and worst would be hard coding constants. However depending on what you’re doing any of those could be good.

If youre 100% sure that they will never ever change just put the values in the constructors.

For example abstract base class Character has the members listed above and accepts them in the ctor. Derived class Knight passes in his values etc. So to make it last longer and be more flexible you can put together a unity editor window with some inputs that export to xml with for each character type, then in your ctor you can read the xml/database.

Using a base class like that allows for methods that accept Character parameters so you can do your calculations in one place instead of having separate/duplicated ones for each character.

To take it one step further use a list of stats instead of a finite set of members. If you make your list recursive that opens a lot of possibilities as well cause now you have a character with a sword with an enchantment which each add to attack so in your stats class just either inherit from a stat list like class Stat : List or contain it and provide a method that calculates the value. This way when you call your Character.Fight() or whatever it can sum up all his equips/buffs and things attached to those.

Probably make some interface like ITarget which has that calculation method so in unity you can just to a raycast on some enemies and get a list of ITarget and pass each one some combat value. Proceed to epic developer status.

XML or a database for this use case is overkill. Use the code as you are if that’s working for you, and you say it is.

If all your characters have the same variables you are just defining a class. Create a Character class with those fields and set them in the constructor:

public Class Character {
   byte move = 3;
   byte range = 2;
   byte attack = 2;
   byte defense = 5;
   byte maxHealth = 5;

   public Character(byte setMove, byte setRange, byte setAttack, byte setDefense, byte setMaxHealth) {
      move = setMove;
      range = setRange;
      attack = setAttack;
      defense = setDefense;
      maxHealth = setMaxHealth;
   }

}

Then you can create different characters like this:

Character myCharacterA = new Character(3, 2, 2, 5, 5);
Character myCharacterB = new Character(3, 4, 1, 2, 4);