- Home /
Amount changes in script but not in Image fill Amount
It's working while displaying health bar but not for hunger and thirst
private void Update()
{
if (isSprinting)
{
if (playerStamina <= maxStamina)
{
playerStamina += Time.deltaTime * staminaRegen;
UpdateStamina("StaminaUpdate", 0);
}
}
if (playerHealth >= 0)
{
if (playerHunger >= 0)
{
playerHunger -= Time.deltaTime * hungerDrain;
}
else
{
UpdateHealth("NoVitals", damageMult);
}
if (playerThirst >= 0)
{
playerThirst -= Time.deltaTime * thirstDrain;
}
else
{
UpdateHealth("NoVitals", damageMult);
}
UpdateVitals("Normal", 0);
}
}
public void UpdateHealth(string healthItemType, int value)
{
if (healthItemType == "NoVitals")
{
if (playerHealth > 0)
{
playerHealth -= value / (hungerDamageRate + thirstDamageRate);
healthImage.fillAmount = (float)playerHealth / (float)maxHealth;
}
}
if (healthItemType == "Damage")
{
if (playerHealth > 0)
{
playerHealth -= value;
healthImage.fillAmount = (float)playerHealth / (float)maxHealth;
}
if (playerHealth <= 0)
{
Death();
}
}
if (healthItemType == "Heal")
{
if (playerHealth >= 0)
{
playerHealth += value;
healthImage.fillAmount = (float)playerHealth / (float)maxHealth;
if (playerHealth >= maxHealth)
{
playerHealth = maxHealth;
}
}
}
}
public void UpdateVitals(string vitalType, int value)
{
if (vitalType == "Hunger")
{
playerHunger += value;
if (playerHunger >= maxHunger)
{
playerHunger = maxHunger;
}
}
if (vitalType == "Thirst")
{
playerThirst += value;
if (playerThirst >= maxThirst)
{
playerThirst = maxThirst;
}
}
if (vitalType == "normal")
{
hungerImage.fillAmount = (float)playerHunger / (float)maxHunger;
thirstImage.fillAmount = (float)playerThirst / (float)maxThirst;
}
}
void Death()
{
Debug.Log("You died lmao");
}
}
Comment
Your answer
Follow this Question
Related Questions
How do you get Old OnGUI Scripts to work with the New UI Scrollbars? 0 Answers
My UI Buttons stopped working 0 Answers
rich text issue 3 Answers
How to drag objects from UI into scen 3 Answers
Invalid Layer Index? 1 Answer