Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 patrickdib007 · Dec 04, 2020 at 02:18 AM · level-designbarfill

Fill Experience Level Bar fast to slow

Hi, I made a level bar fill which goes from 0 to 1 for each level acquired. The value is a float. It increases with potions. I want the bar to go fast in the beginning and slower as it reaches it's target level/Exp.

The problem is that if I increase the level from 1 to 20 using Time.deltaTime. It goes towards the targeted level but at the same speed. I tried different Mathf as well. Some do the trick but since the value is a float, towards the end of reaching the targeted level is becomes REALLLY slow. Which is something I don't want.

Is there a way for me to control the speed depending on the experience bar reaching the targeted level? Thanks

Here's my code using Mathf.MoveTowards :

 ExperienceSlotUI[] expSlots;
 LevelWindow levelWindow;
 [SerializeField] public Button levelUpBtn;
 public Animation anim;
 [SerializeField] ParticleSystem particle;
 [SerializeField] ParticleSystem particle2;
 public int currentLevel;
 public int level;
 public float speed = 0.5f;
 public float XpToAdd;//For ExpSlotUI;
 private float target = 0;


     private void UpdateAddExperience()
     {
         
         if (levelWindow.expBarImage.value < target)
         {
             levelWindow.expBarImage.value = Mathf.MoveTowards(levelWindow.expBarImage.value, target, speed);
             
         }
         if (levelWindow.expBarImage.value >= 1)
         {
             IncreaseOriginalBar();
             ShowExperience(0);
         }
         if(levelWindow.expBarImage.value >= target)
         {
             isAnimating = false;
             //Restart XpToAdd
             XpToAdd = 0;
             //Faire disparraitre un mask transparent
             Destroy(mask);
             //activate btn
             EnableExpBtn();
             //Deactivate particle effect
             particle.Stop();
             particle2.Stop();
 
         }
     }
 
    private void LevelUP()
    {
         levelWindow.expBar2Image.gameObject.SetActive(false);
         levelWindow.expBarImage.gameObject.SetActive(true);
 
         ShowExperience(XpToAdd);
         //Faire apparaitre un mask transparent
         SetupMask();
         //Reset expUsed
         ResetExpUsed();
        
         
         
         //Add to baseStats
         levelWindow.baseStats.IncreaseXP2((int)(XpToAdd));
 
         //Deactivate levelup btn
         levelUpBtn.enabled = false;
     }
 
     private void ShowExperience(float expToAdd)
     {
         target = ((levelWindow.baseStats.GetPoints() + expToAdd) / levelWindow.baseStats.GetRequiredXPForLevel(currentLevel));
         isAnimating = true;
         
     }: 



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
0

Answer by Pokedlg3 · Dec 04, 2020 at 02:42 AM

You can use Time.deltaTime. It is mostly used to leave movements, positions, rotations, scales in a smooth transition time. However, you can decrease it by dividing it, in the same way that you use * to multiply and increase the speed, you can use / to decrease the speed. Example:

 Time.deltaTime / 5

Comment
Add comment · 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

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

138 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 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

progress bar 1 Answer

Stop Timebar decrease by pressing key button 1 Answer

How to do slowly rising bar? 1 Answer

How to change Android navigation/status bar color? 0 Answers

How do I do Image fill for HP bars that % of player health? C# 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