How to go about this concept

hello, I’m not sure if this is the right thread category for this so sorry if its not

i am currently working on a TBS game and i currently have a small working project that spawns a unit prefab on a map of nodes and i got working for movement. what i want to now is spawn a few different units with a variety of different attributes i.e. health, defense, and how far it can move per turn. i am just curious what is the best way to go about doing this. should i make a script for each unit type like Knight has 10 health , 50 def. and can move two spaces per turn, then make a different script for an Archer has 10 heal, 20 def. and can move 6 spaces per turn.

i looked into “inheritance” and i don’t think i would like to do that as there will be many variables with each unit i think for that to be valuable

just looking for some direction, suggestions, documentation, videos

thanks

Make a single script with empty values. Then set the values for each unit type in the inspector, probably on a prefab.

What @Kiwasi said works very nicely, but I think I would take it one step further and make a ScriptableObject that defines the unit. You would make instances of this ScriptableObject and fill the fields in with qualities you want.

You could also break it down into a Mobility object, an Armament object, etc., and have the fields related to each of those qualities individually contained. That way you could have far more variety without a lot of data duplication: You might have three tanks that are all the same Mobility, but they all have different Armament objects.

Then you can just drag/drop those ScriptableObjects into fields in your Prefab scripts to make the variations.

2 Likes

thanks thats i think what I’m looking for