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;
}: