Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by LordOfTheOtters · Aug 30, 2020 at 11:15 AM · variablesclassintvaluesstorage

Best way to store RPG job experience?

Apologies if this is the incorrect place to ask this question, I am new to Unity and game development. I am making an RPG for the first time and am working on how jobs/classes work. I would like to add a system where enemies will give players "Job EXP" that will go towards their "Job Level". Each job a character holds will have 3 values: "Current Job Level", "Job Experience" and, "Job Experience Required For Next Level". I am unsure of the best way to store all this information.

Currently the solution in my mind is to have them all as separate int values. But if I decided to have, say 20 jobs available in the game, then that's 20 X 3 values - 60 different fields within my character class. With 4 party members that makes 240 fields to hold all that information. Is that too much? Does anyone have a method of storing these values that takes up less space, or makes more sense? Any help is appreciated and I can provide code if needed!

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
1

Answer by Hellium · Aug 30, 2020 at 12:10 PM

No, having 3 individual integers for each job directly stored in your Player is not a good idea.

Why don't you store the job information in its own class & create an array in your Player class?

 [System.Serializable]
 public class Job
 {
     [SerializeField] private string name;
     [SerializeField] private int currentExperience;
     [SerializeField] private int[] experienceTresholdsToNextLevel; // 10, 100, 1000, .... or whatever

     public string Name { get { return name; } }
     public int CurrentExperience { get { return currentExperience; } }

     public int Level()
     {
         int level = 0;

         while(currentExperience > experienceTresholdsToNextLevel[level])
         {
             level++;
         }

         return level;
     }
 }

 public class Player : MonoBehaviour
 {
     [SerializeField]
     private List<Job> jobs = new List<Job>();

     public void LearnJob(Job job)
     {
         jobs.Add(job);
     }
 }
Comment
Add comment · Show 1 · 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 LordOfTheOtters · Aug 31, 2020 at 02:02 AM 0
Share

This looks like a great way to do it which I hadn't considered, and it should fit nicely into my existing code! I'll give this a shot and let you know if it all works well! Thanks very much!

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

138 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Convert class of int vars into an array 0 Answers

Inspector won't update with new variables.,Variables don't seem to update on inspector 0 Answers

What is the best way to store data about a GameObject? 1 Answer

How do I save an array of all different variables? 0 Answers

How to use if statements for inspector in class? 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