- Home /
storing character stats
Im not sure how many of you have played final fantasy, but you have a team of up to 4 players, each of different stats.
I'm trying to achieve something similar.
Strength, Defense, Vitality etc so each player has its own individual stats.
Would it be best to store this all in one c# script, with a custom class holding these variables then have a list of these classes? Im not sure on what the best way to go about doing this would be.
Examples or a nudge in the right direction wouldn't go a miss, thanks in advance!
Answer by Waz · Jul 13, 2011 at 09:34 PM
In my rpg, I have a Creature class which has INT, STR, etc. variables, each of type Stat. I also have an array of those same objects to simplify bulk processing, and an enum that corresponds to the array positions for nice presentation in inspector variables. The player and every monster is an instance of Creature.
Having a Stat class allows me to store buffs etc. while still having the base stat values available. I also use it to encapsulate stat change messages as well as generating floating visual +1s.
But there is no "right" way. You might just have:
var INT : int;
var STR : int;
...
In you Player class. Indeed, I think that's what I started with. It's better to write simple, maintainable, evolvable code and refactor as-needed rather than to start with something that may be unnecessarily complicated.
ok a step in the most efficient direction*
example of what im trying to achieve
$$anonymous$$m:
player 1:
str - 1
def - 3
int - 2
player 2:
str - 2
def - 3
int - 2
player 3:
str - 2
def - 1
int - 1
player 4:
str - 3
def - 2
int - 3
would this best be stored in 1 script? and saved in playerprefs?
I would suggest that you at least have a "Character" script with the stats, and 4 instances of that script in your 4 characters.
Storage or serialisation of your game is a whole other question, but yes, PlayerPrefs is fine - that's what I use.
but the thing is, each player wont always have its own GameObject, only in a battle will the other players be intantiated!
Create an independent, persistent game manager and stick all your stat data in it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612142829im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get user gameplay data for testing? 1 Answer
How to check which gameobject is the player using 2 Answers
Trouble Adjusting Stats (MP After Casting A Spell) 2 Answers
How to differentiate between players in multiplayer game 1 Answer
How can I make player move with cursor?,How can I make player move with mouse? 1 Answer