Start refilling a fill bar every 100 levels

Hi everyone, I would need some help with scripting.

I have a casual game with 1000 levels.

I am trying to build a refill system, that fills up when reached level 100, then give a reward, and start filing over again till level 200, and the same thing repeats again.

I can fill the bar till lv 100, but how to restart it again and again?

Thank you for any useful input!

here is my script:

void Setlevelprogress()
{
float currentlevelvalue = prefmanager.instance.Getlevelsvalue();
levelValue.text = currentlevelvalue.ToString();
var fillvalue = currentlevelvalue / 100f;
Levelfillbar.fillAmount = fillvalue;
if (levelvalue == 101)
{

Debug.Log(“reached lv 100”);
//restart filling
//some animation
List fromPositions = new List();
for (int i = 0; i < categoryCoinsAwarded; i++)
{
fromPositions.Add(categoryCoinPrizeIcon);
SoundManager.instance.PlayRewardfalSound();
}
CoinController.Instance.AnimateCoins(categoryCoinsAmountFrom, categoryCoinsAmountTo, fromPositions);
categoryCoinPrizeIcon.gameObject.SetActive(false);
coinController.AnimateCoins(categoryCoinsAmountFrom, categoryCoinsAmountTo, fromPositions);
}
}

What values does the method prefmanager.instance.Getlevelsvalue() return? From 1 to 100, or from 1 to 1000? Perhaps you just need a condition where the current level number modulo 100 returns 0? I mean if(prefmanager.instance.Getlevelsvalue() % 100 == 0) will trigger every time the level is a multiple of 100 (0, 100, 200, 300, etc.).

1 Like

Thanks, but how to start refilling the bar again?

If you want the bar to appear at 25% on levels 25/100, 125/200, 225/300, then you would just set the bar to the modulo. It works the same as the hour hand of a clock.

var fillvalue = (currentlevelvalue % 100f) / 100f;

Read up on how the modulo (%) operator works in mathematics. It’s like the remainder of a division.

1 Like

wow! thanks a lot! I will try :slight_smile: