// Runs until the animat is dead // Animat uses reasources over time // If it runs out of reasource it instad loses health // If it runs out of health it dies IEnumerator Metabolism() { while (dead != true) { // Resource to health conversion if (thirst > baseHydration / 3 && hunger > baseSatation / 3 && health < startingHealth) { health = Mathf.Clamp(health + health / 10, 0, startingHealth); thirst = Mathf.Clamp(thirst - (int)(baseHydration / 20), 0, baseHydration); hunger = Mathf.Clamp(hunger - (int)(baseSatation / 20), 0, baseSatation); //Debug.Log(gameObject.name + "Gained health: currentHealth = " + health); } // Thirst level if (thirst != 0) { thirst = Mathf.Clamp(thirst - ((int)(baseHydration / 10) + 1), 0, baseHydration); //Debug.Log(gameObject.name + ": thrist = " + thirst); } else if (health != 0) { health = Mathf.Clamp(health - (int)(startingHealth / 20), 0, startingHealth); //Debug.Log(gameObject.name + ": health = " + health + "due to Dehydration"); } else { spawnOrigin.AddData(0); Die(); } // Hunger level if (hunger != 0) { hunger = Mathf.Clamp(hunger - ((int)(baseSatation / 20) + 1), 0, baseSatation); //Debug.Log(gameObject.name + ": hunger = " + hunger); } else if (health != 0) { health = Mathf.Clamp(health - (int)(startingHealth / 20), 0, startingHealth); //Debug.Log(gameObject.name + ": health = " + health + "due to Stavation"); } else { spawnOrigin.AddData(0); Die(); } yield return(new WaitForSeconds(metabolicRate)); } }