- Home /
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;
}:
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613021033im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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