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
0
Question by Dionysos1111 · May 24, 2018 at 04:34 PM · xp

Level and XP system

Hi,

I made an xp system with this tutorial: XP System

This is what i have:

     public float XP;
     public int CurrentLevel;
     public float XpNextLevel;
     public float differenceXp;
     public float TotalDifferences;
     public Text XpText;
     public Image XpBar;
     public Text Level;
     private int LevelUp;
     public IncreaseStats Stats;
     public LevelUp Up;
     public AudioSource LvlUp;
 
 
     private void Start()
     {
         UpdateXp(0);
         XpText.text = (TotalDifferences - differenceXp).ToString("0") + "/" + TotalDifferences.ToString("0");
     }
 
 
 
     public void UpdateXp(float xp)
     {
         XP += xp;
         int curlvl = (int)(0.1f * Mathf.Sqrt(XP));
         if(curlvl != CurrentLevel)
         {
             LevelUp = curlvl - CurrentLevel;
             CurrentLevel = curlvl;
             LvlUp.Play();
             Stats.AddSkillPoints(LevelUp *2);
             Up.Up();
 
         }
         XpNextLevel = 100 * (CurrentLevel + 1) * (CurrentLevel + 1);
         differenceXp = XpNextLevel - XP;
 
         TotalDifferences = XpNextLevel - (100 * CurrentLevel * CurrentLevel);
 
         XpText.text = (TotalDifferences - differenceXp).ToString("0") + "/" + TotalDifferences.ToString("0");
 
         XpBar.fillAmount = 1 / TotalDifferences * (TotalDifferences - differenceXp);
         Level.text = (CurrentLevel + 1).ToString("0");
     }


The thing is when i level up now, the first level is 100XP, then the next level is 300, and next 500 etc.

So it just goes up with 200XP every level i went up instead of in the video explained a nice curve.

What am i doing wrong?

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

Answer by blanktarget · May 24, 2018 at 05:40 PM

You need to have an exponent. I recently set this up in my game too.

Here is how I made a ramp of levels in an array to look at. In this case you can set your toLevelUp.Length to however many levels you want. An important thing to note here is that "i" starts at 1, because right now in my code at least level 0 is 0 xp so you instantly level up to 1. Just made things easier for how I coded the rest. Also, baseXP should be however much XP it takes to get to level 2. From there it goes up!

 //XP ramp up
     void LevelXPSetUp(){
         for (int i = 1; i < toLevelUp.Length; i++) {
             toLevelUp[i] = (int)(Mathf.Floor(baseXP*(Mathf.Pow(i,1.5f))));
         }
     }


I see you have an xp bar you want to fill up too on screen it looks like? I made it so mine fills over time too instead of jumping to the value. It looks nicer to see your xp bar fill instead of just suddenly being full.

This is what mine looks like:

 //should count up until it hits the experience amount to add.
     public IEnumerator AddExperience(int experienceToAdd){
         addingXp = true;
         //received from external sources. Add xp incrementally to move bar up slowly instead of chunks.
             for (int i = 0; i < experienceToAdd; i++) {    
             currentXPAmount++;
                 yield return new WaitForSeconds (.002f);
             }
         addingXp = false;
     }

Comment
Add comment · 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

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

83 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

Related Questions

XP and Collision in Unity2D 0 Answers

Unity dont start after installation - XP 3 Answers

No version of Unity 3D working... 0 Answers

Unity 2017.4.3f1 windows standalone build does not run in windows xp 0 Answers

Unity3d not working properly on a WinXP 64 platform? 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