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
-2
Question by DarkZero208 · Feb 02, 2014 at 01:35 AM · levelsystemexperiencexp

Xp Calculation Bar

Hello well I have this experience system but it's all right but when I get more xp than need the bar just get out of the screen and the level just keep going Up how do I write something that for example I have 200 xp and I need 700 for level up but I kill a monster that give me 1000 xp so I want to know how can I make when xp gets to 700 the xp bar goes to 0 and the restant xp adds to the bar so the bar will grow only the restant xp

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 ffxz7ff · Feb 02, 2014 at 01:39 AM 0
Share

"I need something" isn't a question.

avatar image DarkZero208 · Feb 02, 2014 at 11:09 AM 0
Share

I'm not trying to get things for free you can just give an explanation on how to calculate, I'm not telling you "HEY GIVE $$anonymous$$E A SCRIPT FOR WHAT I NEED" so forgive me for expressing myself poorly maby it's was my mistake to explain like that but you dont have to comment if you don like

avatar image SirGive · Feb 05, 2014 at 03:44 AM 1
Share

did you check this question: http://answers.unity3d.com/questions/125359/rpg-algorithms.html

avatar image DarkZero208 · Feb 12, 2014 at 07:16 AM 0
Share

actually nope I will thanx for the info.

1 Reply

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

Answer by RyanZimmerman87 · Feb 02, 2014 at 01:57 AM

One way to handle this it use OnGUI() to draw the bars for you. Here's a quick example of the OnGUI() stuff:

 //formatting style for OnGUI
 public GUIStyle XPStyle;
     
 //textures for empty and full xp bar
 public Texture2D emptyXPTexture;
 public Texture2D fullXPTexture;
 
 
 
 //formatting vector
 Vector3 matrixVector;
 
 //position and size for texture bars    
 Vector2 XPVectorPosition;
 Vector2 XPVectorSize;
 
 //formatting size example
 float native_width = 1280; 
 float native_height = 720;
 
 //this float is the % of the visual bar being filled
 float barDisplay;
 
 //example variables
 float playerCurrentXPRequired;
 float playerLastXPRequired;
 
 
 void Start() 
 {
 //prepare matrix variables
 rx = Screen.width/ native_width;
 ry = Screen.height / native_height;
 
 //set matrix for OnGUI formatting
 matrixVector = new Vector3 (rx, ry, 1);
 
 
 //set the position and size for your xp bar
 XPVectorPosition = new Vector2 (0, 0);
 XPVectorSize = new Vector2 (500, 50);
 
 }
 
 void OnGUI()
 {
 //calculate the % of XP bar to be filled
 barXPDisplay = (GlobalDataScript.playerXPTotal - playerLastXPRequired) / (playerCurrentXPRequired-playerLastXPRequired);
 
 
 //formatting matrix
 GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, matrixVector); 
         
 //draw the bars first empty than full
 GUI.BeginGroup(new Rect(XPVectorPosition.x, XPVectorPosition.y, XPVectorSize.x, XPVectorSize.y),emptyXPTexture, XPStyle);
             
 GUI.BeginGroup(new Rect(0, 0, XPVectorSize.x * barXPDisplay, XPVectorSize.y));
 GUI.Box(new Rect(0, 0, XPVectorSize.x, XPVectorSize.y), fullXPTexture, XPStyle);
             
 GUI.EndGroup();
 GUI.EndGroup();
 
 //can display text of how much xp you have and how much xp you need to level up
 //adjust these position variables
 GUI.Label (new Rect (0, 0, 0, 0), "" + GlobalDataScript.playerXPTotal + "/" + playerCurrentXPRequired
 + " XP", XPStyle);    
 }
 
 //whenever you gain XP call this function
 public void XPUpdateFunction()
 {
 //code to determine if you leveled up when you gain xp
 //code to set all the new variables if you leveled up
 }


Apologies for the formatting, whenever I copy example stuff out of my current project it gets a bit hard to manage it to look perfect.

Hopefully that will get you started with displaying the bar visually.

I'm not sure if your question was mainly based on the bar visuals or the actual logic required to level up. But this should cover the visual stuff which is a bit more difficult if you are new to Unity.

I would recommend figuring out the leveling up logic yourself since it should be specifically designed for your game.

I try to name my variables so they are somewhat self explanatory but I don't have time to outline what each one is exactly for the XP stuff, but hopefully this helps.

Comment
Add comment · Show 3 · 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 DarkZero208 · Feb 02, 2014 at 05:34 AM 0
Share

well tnhx for the explanation but the visual part I got it solved i was attendig more for the logic xD maby I miss explain but thanx

avatar image RyanZimmerman87 · Feb 05, 2014 at 03:42 AM 0
Share

Oh dangit, was worried that might be the case.

Do you have a specific problem with the logic? Is their something you don't understand how to do with the program$$anonymous$$g?

This just really seems like one of those things that you would benefit a lot more from by solving yourself then trying to copy someone. Setting up your leveling system is a good mental exercise and good practice if you're new to program$$anonymous$$g.

It really shouldn't be too overly difficult in the grand scheme of game program$$anonymous$$g but if you have a specific question I could try to help.

avatar image DarkZero208 · Feb 05, 2014 at 04:03 AM 0
Share

Thanx I'll keep that in $$anonymous$$d but before I will try to mae it my seft xP

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

21 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

Related Questions

How can i make it give u a certain xp everytime u kill someone? 1 Answer

Using static members vs normal ones for exp,lvl, health ect.. 1 Answer

Can't use System.IO.FileInfo.Delete 1 Answer

Level unlock system 1 Answer

Dynamic Level Progress Bar 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