Updating UISlider with value from variable.

Hi all,

I am using a slider to display a players current stamina. Very basic issue I am having here -

Why does this code:

	if(currentStamina >= 0)
		{
			currentStamina += Time.deltaTime * 2f;
		}

cause the UISlider to refill faster than this code:

if(currentStamina >= 0)
		{
			currentStamina += Time.deltaTime * staminaRegenRate;
		}

even when staminaRegenRate is declared as a public float with a value of 2f? Also, where should I be making the statement:

staminaBar.value = currentStamina;

Currently I have it at the bottom of Update().

Thanks!

Make sure you assign the value to staminaRegenRate in start() or in the editor. If you assigned it as a default value in your class, that value will be overwritten by whatever value you have in the editor, at game launch.

Debug.Log() is your best friend when you are getting unexpecteed results like that. What does Debug.Log() say the actually value of staminaRegenRate is?

Update() should be a good place to update the slider value.