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 /
  • Help Room /
This question was closed Mar 11, 2016 at 07:40 PM by Entyro for the following reason:

The problem is fixed!

avatar image
0
Question by Entyro · Mar 06, 2016 at 11:50 AM · javascriptscripting problemguixp

Level up system problem

Hello there!

Right now I'm working on a level up system script but I've encountered a problem.

When I get XP, the XP bar moves outside the box (look at the image). When I'm level 1 it works fine, but when the XP amount increases when I'm level 2 or more the XP bar is acting strange.

It should be so when the amount of XP that is required to level up increases, the amount of XP that adds to the XP bar should look smaller, but now it adds the exact same amount (same width), so that's why It goes outside the box.

alt text

Does anyone know how to fix this problem?

Script

 var guiSkin : GUISkin;
 var levelTexture : Texture;
 var levelBGTexture : Texture;
 var levelUpSound : AudioClip;
 
 var currentXP : float = 0;
 var maxXP : float = 100;
 var level : float = 1;
 
 private var leveledUp : boolean = true;
 
 var GUIControllerScript : GUIController;
 
 
 function Update () 
 {
     if(currentXP >= maxXP)
     {
         levelUpSystem();
     }
     if(leveledUp)
     {
         leveledUp = false;
     }
 }
 
 function levelUpSystem ()
 {
     currentXP = 0;
     maxXP = maxXP + 50;
     level++;
     AudioSource.PlayClipAtPoint(levelUpSound, transform.position);
     leveledUp = true;
 }
 
 function OnGUI()
 {
     GUI.skin = guiSkin;
     GUI.depth = 0;
     
     if(GUIControllerScript.GUIOn)
     {
         GUI.DrawTexture(new Rect((Screen.width / 2) - 165, 20, 300, 30), levelBGTexture);
         GUI.DrawTexture(new Rect((Screen.width / 2) - 165, 20, 3 * currentXP, 30), levelTexture);
         GUI.Box(new Rect((Screen.width / 2) - 165, 20, 300, 30), currentXP + "/" + maxXP, "level");
         GUI.Box(new Rect((Screen.width / 2) - 335, 20, 300, 30), level + "");
     }
 }


img.png (260.8 kB)
Comment
Add comment · Show 5
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 savlon · Mar 06, 2016 at 07:36 PM 0
Share

The GUI system you are using is deprecated and complex to implement correctly. You should use the new UI system as it would make your intended action a whole lot simpler.

avatar image TonicMind savlon · Mar 06, 2016 at 08:02 PM 0
Share

$$anonymous$$aybe a something better to say would be: which version of unity are you using OP, and why? Perhaps he or she doesn't want to upgrade and break his code/deal with the current issues.

[edit] On a second thought: perhaps you ought to exa$$anonymous$$e your mathematics on the placement and scaling of your textures. It may just be a simple arithmetic or multiplication issue. I encourage you to start from the beginning of your code doing the math by hand. You will probably find the problem that way. I've got a pretty good indication that the problem is related to your currentXP variable, and how you give the drawTexture function parameters.

Lastly, this is a semi good question, because you provided both a screenshot and some code. In the future please try to solve things yourself, or you will stunt your own personal growth as a programmer! We haven't seen any indication that you've actually tried to solve this yourself (none that you've mentioned at least).

avatar image Entyro TonicMind · Mar 07, 2016 at 03:05 PM 0
Share

I'm using Unity 5.0, so I can use the new UI system if I want, but all of my scripts have the old system so I think I will stick with that right now. I've tried some things to solve this but I haven't managed to fix it yet.

Scripting isn't my best feature, I'm more of a designer :)

Show more comments
avatar image TonicMind · Mar 14, 2016 at 09:13 PM 0
Share

@$$anonymous$$tyro good job! I knew you could do it :)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

71 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

Related Questions

Carrying an object using Javascript 0 Answers

Move Button as soon as its klicked to the bottom Screen 1 Answer

Object move around side window 0 Answers

What's wrong with my script? 2 Answers

Noob Here... Can you please give Script for moving a object into random Direction. 0 Answers


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