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 jeffreywarf · Sep 28, 2012 at 01:29 AM · guitextrpg

RPG Levelling Script using GUI Text help

I am trying to modify an old script I have meant for showing and modifying a score that the player gets from destroying gameobjects into a levelling up script. So far the script works find for showing the current experience and even works with levlling up, but only up to level 2. Once level 2 is reached then the level up script ceases to work in that it stops changing the experience needed to level up and level when the current exp is greater than or equal to the experience needed. Here is the code that I have so far (sorry for the remnants of the old script cluttering it up):

 var hitTag = "bullet";
 var hitName = "bullet";
 var points = 10;
 
 static var current_xp = 0;
 var EXP_TO_LEVEL = 100;
 var user_level = 1;
 var exp_text : GUIText;
 var level_text : GUIText;
 var modify_exp = 1.5f;
 var xp_given = 10;
 
 function Update () {
 }
 
 function 
 ScorePoints()
 {
     gameObject.FindWithTag("Player").SendMessage("ScorePoints", points);
 }
 
 function addxp()
 {
         gameObject.FindWithTag("Player");
         current_xp += xp_given;
         if(current_xp >= EXP_TO_LEVEL)
         {
             user_level++;
             EXP_TO_LEVEL = Mathf.FloorToInt(EXP_TO_LEVEL * user_level * modify_exp);
                 
         }
 }
 
 function updatetexts()
 {
         exp_text.text = (current_xp.ToString() + "/" + EXP_TO_LEVEL.ToString());
         level_text.text = ("Level: " + user_level.ToString());
 }
 
 
 function
 OnTriggerEnter(col : Collider)
 {
 
 
     if ((col.gameObject.tag == hitTag) || (col.gameObject.name == hitName))
     {
         Destroy(col.gameObject);
         Destroy(gameObject);
         Debug.Log("Trigger " + col.gameObject.tag);
         addxp();
         updatetexts();
     }
 
 
 }
 
 function
 OnCollisionEnter(col : Collision)
 {
     Debug.Log("BBBB Collision " + col.gameObject.tag);
     if ((col.gameObject.tag == hitTag) || (col.gameObject.name == hitName))
     {
         Destroy(col.gameObject);
         Destroy(gameObject);
         Debug.Log("AAAAA Collision " + col.gameObject.tag);
         current_xp++;
         user_level++;
         addxp();
         updatetexts();
         EXP_TO_LEVEL++;
     }
 }
Comment
Add comment · Show 4
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 kmeboe · Sep 28, 2012 at 02:22 AM 0
Share

Sheesh...that is one draconian XP system. You do realize the xp needed to level will look about like this: 100, 300, 1350, ~7000, etc. You might want to rethink that a bit. :)

But to the problem at hand: I notice that you're incrementing level each time the player hits an object (in OnCollisionEnter()). Seems like all of those increments should be removed, as they are all handled inside addxp().

Can you clarify what exactly is going wrong? Have you set a breakpoint inside of addxp()? Does the XP continue to climb?

avatar image jeffreywarf · Sep 28, 2012 at 04:32 AM 0
Share

You make a good point about that XP system. I had a C++ program run the math and it would be too ridiculous just by level 20. What the problem is that once level 2 is reached, I can keep gaining on the current_exp side, but once it becomes greater than or equal to the EXP_TO_LEVEL to get to level 3 it never turns over to the level 3. Or at least it didn't. I actually fixed the code and got it working by changing EXP_TO_LEVEL and user_level to static variables. I don't know why that made a difference but it did.

What would be suggested about the levelling algorithm to be less... draconian?

avatar image MD_Reptile · Sep 28, 2012 at 04:59 AM 0
Share

I think he means it would be way too long to get to the higher levels, that the increase of experience needed is too high. Just make it only like 10-20 percent harder than the last level, and make tougher baddies (that you only fight in harder levels) worth more xp.

avatar image kmeboe · Sep 28, 2012 at 06:32 AM 0
Share

$$anonymous$$D_Reptile's got it. So like if level 1 is 100, then level 2 is 220 (total XP), and level 3 is like 360. Basically just keep track of how much XP it is to get from level to level, and multiply that by 1.2 each time or something.

Congratulations on figuring out your solution.

0 Replies

· Add your reply
  • Sort: 

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

12 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

Related Questions

Multiple Cars not working 1 Answer

GUIText dissapear after a few seconds 2 Answers

Score System help 1 Answer

Climbing script 0 Answers

My character will fall through the floor with this script:... 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