• 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 Zyphen · Mar 09, 2013 at 06:03 PM · gamelevelplayupleveling

can figure out why it starts at level 2

hello! i am a bit of a noob when it comes to unity and ive run into some trouble, ive made a level up script and at the moment pushing r adds experience to it and eventually you level up, now my problem is you start out at level 2 and not 1 and i cant figure it out.

here is the code

 var curHealth : int = 100;
 var maxHealth : int = 100;
 
 var healthtext : GUIText;
 
 var curXp : int = 0;
 var maxXp : int = 0;
 
 var xptext : GUIText;
 
 var level : int = 0;
 
 function Start () {
 
 
 healthRegen();
 
 }
 
 
 
 
 
 function Update () {
 
 
 healthtext.text =  "Health " + curHealth + " / " + maxHealth;
 
 xptext.text =  "Level : " + level + " XP: " + curXp + " / " + maxXp;
 
 if(curXp == maxXp)
 {
     levelUpSystem();
 
 }
 
 
 
 if(curHealth < 0 ) {
 
 curHealth = 0;
 
 
 }
 
 
 if(curHealth > maxHealth) {
 
 
 curHealth = maxHealth;
 
 
 }
 
 
 
 if(Input.GetKeyDown("e")) {
 
 curHealth -= 10;
 
 }
 if(Input.GetKeyDown("r")) {
 
 curXp += 10;
 
 }
 
 
 }
 
 
 
 
 function healthRegen () {
 
 
 for(i=1;i>0;i++) {
 
 
 
 yield WaitForSeconds(0.5);
 
 if(curHealth < maxHealth) {
 
 curHealth++;
 
 }
 
 
 }
 
 
 }
 
 
 function levelUpSystem () {
 
 
 curXp = 0;
 maxXp = maxXp  + 50;
 level += 1;
 
 maxHealth += 20;
 
 
 
 }

 
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
Best Answer

Answer by ByteSheep · Mar 09, 2013 at 06:12 PM

You simply have to make maxXp greater than null at the start. Since if it is set to zero you will level up right away.. Try setting maxXp to 50. Let me know if this works or if you have already set it higher than 0 in the inspector!

Comment
Add comment · Show 2 · 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 Zyphen · Mar 09, 2013 at 09:35 PM 0
Share

YAY! yeah that worked perfectly, was actually quite a stupid question now i think about it. thank you!

avatar image ByteSheep · Mar 09, 2013 at 09:38 PM 0
Share

No problem, If you like you can mark this answer as accepted so your question doesn't appear as unanswered anymore ;)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

Implementing Level ID 0 Answers

Playing Game Outside Unity 2 Answers

How do you add levels to your game? 1 Answer

Level creator save bug. 0 Answers

Realistic game 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