I’m trying to build a simple character/unit generator for an RPG type game and was hoping to get some help with some fairly general sort of questions I’ve got.
Note I’m not trying to build an avatar system, just assume the models are simple cubes. And it probably doesn’t make a difference but the RPG will be turn based.
So every unit will have some stats (strength, agility etc), some resources (HP, MP, etc), a race (elf, dwarf, human) and some skills/abilities.
The first thing I was wondering is what would be the most common / reasonable approach to structuring my units? The approach I was thinking of was having a bunch of base classes (base unit, base race, base stats, base HP, etc) and just adding them as objects/components to my gameobject. Are there any potential/obvious gotchas with this approach? I estimate that I’d probably end up with maybe a dozen or more components on each unit, all holding a small amount of data.
Secondly the numerical stat values with initially be determined by race. Assuming I’ll be adding more races later on, would it make more sense to store stat values in a separate class for each race? Or do the assignments in the character creation script? (i.e if (elf) then unit.str = x)
Finally how do I associate my unit data with the actual game object? Would I do it using getcomponent?
I’ve actually done that tutorial already and while it was some help, it didn’t really tackle the same sort of thing I’m trying to accomplish, which is a flexible, component based system for generating characters dynamically.
I suppose you could use ScriptableObjects. Then you have the ScriptableObject “assets” stored with the data you want and the character would be defined by whatever asset is being referenced. Similar to a prefab just with data done by reference.
Hmmm, well I’ve never done something along the lines of what you are doing, But I have attached scripts to player and non player objects that have; health, color & style, spawn points, and AI interaction parameters. Depending on the circumstances, I’ve made a Uni-character and can be set in code to any character and any character option available.
Health is a universal parameter that can be used in all characters. Zero health is dead. Damage factor is what can be different from character to character. Find what is common and what is not with all your characters, and then decide how to handle. An uber-script with modifications for different characters or different scripts for each character type, there is no right way. Do it the way it makes sense to you. Even if there is a better way of doing it, you still got it working and you gained a lot of knowledge in the process.
Failure is learning, don’t be discourage by it, it’s simply a challenge to try again.
Turns out I’m a dummy; I had a script, the general idea was to spawn a cube, fill some custom script components with data and then attach them to the cube.
What I needed to be doing was have two scripts: One that spawned a cube(s) and attached the second script, the second script attaches the components to the cube and fills them with data. Once I’d figured that out the rest got a lot easier.