public void ModifyCurrentHealth(float value) { currentHealth = Mathf.Clamp(currentHealth + value, 0f, maxHealth); HealthStatus = ComputeStatStatus(currentHealth, maxHealth); if (currentHealth == 0) { agent.Death(); } }
public void ModifyHunger(float value_kcal) { float nonClampedHunger = currentHunger + value_kcal; currentHunger = Mathf.Clamp(nonClampedHunger, 0f, maxHunger); HungerStatus = ComputeStatStatus(currentHunger, maxHunger); if (HungerStatus == ObservableStatStatus.Max) //Starving { float deficit_kcal = nonClampedHunger - maxHunger; //Debug.Log("Starving!!! " + "kcal deficit: " + deficit_kcal); ModifyCurrentWeight(-deficit_kcal / kcalPerWeightUnit); } else if (HungerStatus == ObservableStatStatus.None) //Excess kcal stored in weight { float excess_kcal = Mathf.Abs(nonClampedHunger); ModifyCurrentWeight(excess_kcal / kcalPerWeightUnit); } }