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 josif · Sep 09, 2010 at 03:37 AM · colliderlevelswitchup

level up need help

hello all i got this script that iv been working one today and its got a switch function on and when i get 50 exp i made it that the level (level of character) become level 2 because of the level += 1; any way my prob is that when i get the exp, and it adds up to 50 its adds 1 level really quick so what i want it to do is to just add one level not 1 + level ever second till i go over 50 if you can help thanks

here's the script

var level = 1;

private var ExpUp = false;

static var EXP = 0;

function OnTriggerEnter (hit : Collider) { if(hit.gameObject.tag == "ExpOrb") { ExpUp = true; ExpController.EXP += 25; } }

function Update () { switch(EXP) { case 50: level += 1; break;

     case 150:
         level += 1;
     break;

     case 300:
         level += 1;
     break;

     case 500:
         level += 1;
     break;

     case 750:
         level += 1;
     break;

     case 1000:
         level += 1;
     break;

     case 1300:
         level += 1;
     break;

     case 1600:
         level += 1;
     break;

     case 2000:
         level += 1;
     break;
 }
 print(EXP);
 print(level);

}

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 · Sep 09, 2010 at 03:57 AM

Don't put the level up check in Update (). If you want to take this approach, create a separate function and call it any time you gain experience.

function CheckLevelUp() 
{
    switch(EXP)
    {
        case 50:
        case 150:
        case 300:
        case 500:
        case 750:
        case 1000:
        case 1300:
        case 1600:
        case 2000:
            level += 1;
        break;
    }
}

This isn't a particularly flexible way of handling experience or levels. For example, if you ever have anything that doesn't give 25 experience, you may miss the 'case' and the levelup would never occur. But your question was asking how to get this working, so I've tidied it up for you.

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 josif · Sep 09, 2010 at 04:39 AM 0
Share

if there is other way can you tell me sorry im just a beginner and i wanted to try out the switch function

avatar image · Sep 09, 2010 at 04:47 AM 0
Share

The pseudocode provided in this answer (http://answers.unity3d.com/questions/13334/experience-points-level-up-for-rpg/13369#13369) would be a cleaner way of doing it. Another more-reliable system is posted in http://answers.unity3d.com/questions/18859/experience-system-leveling-prematurely. It depends on what kind of flexibility you want/need. If you'll only ever award the experience in 25 point amounts, the way you've done it will work fine.

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

No one has followed this question yet.

Related Questions

Help with level collider 2 Answers

character switching on collision 1 Answer

Internal collisions 1 Answer

My script isn't detecting OnTriggerEnter why? 1 Answer

Adding colliders to a level 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