void ChangeHungerbar() { if (Hunger == MaxHunger) { HungerBar.GetComponent <Image>().color = Color.red; StarvingText.SetActive(true); if (isWalking) { dieTime += Time.deltaTime; if (dieTime > dieTimer) { if (pupDeath == 0) { Pup1.SetActive(false); Pup1Object.SetActive(false); pupDeath += 1; dieTime = 0; } else if (pupDeath == 1) { Pup2.SetActive(false); Pup2Object.SetActive(false); pupDeath += 1; dieTime = 0; } else if (pupDeath == 2) { Pup3.SetActive(false); Pup3Object.SetActive(false); pauseGameManager.GameOver(); } } } } else if (Hunger > MaxHunger * 0.75f) { HungerBar.GetComponent <Image>().color = Color.red; StarvingText.SetActive(false); } else if (Hunger > MaxHunger * 0.25f) { HungerBar.GetComponent <Image>().color = Color.yellow; StarvingText.SetActive(false); } else { HungerBar.GetComponent <Image>().color = Color.green; StarvingText.SetActive(false); } }
void UpdateHunger() { if (isWalking) { time += Time.deltaTime; if (time >= timer) { if (isHungry) { Health -= 1; } Hunger += HungerGet; time = 0; } } if (Hunger <= 0) { Hunger = 0; } if (Hunger >= MaxHunger) { Hunger = MaxHunger; } if (Health <= 0) { Health = 0; pauseGameManager.GameOver(); } if (Health >= MaxHealth) { Health = MaxHealth; } HungerBar.fillAmount = Hunger / MaxHunger; HealthBar.fillAmount = Health / MaxHealth; }