Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by CarlLawl · Jul 13, 2011 at 09:11 PM · playerstatsstoring

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CarlLawl · Jul 13, 2011 at 09:41 PM 0
Share

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?

avatar image Waz · Jul 13, 2011 at 09:45 PM 0
Share

I would suggest that you at least have a "Character" script with the stats, and 4 instances of that script in your 4 characters.

avatar image Waz · Jul 13, 2011 at 09:46 PM 0
Share

Storage or serialisation of your game is a whole other question, but yes, PlayerPrefs is fine - that's what I use.

avatar image CarlLawl · Jul 13, 2011 at 10:01 PM 0
Share

but the thing is, each player wont always have its own GameObject, only in a battle will the other players be intantiated!

avatar image Chris D · Jul 13, 2011 at 10:04 PM 0
Share

Create an independent, persistent game manager and stick all your stat data in it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges