示例#1
0
 /// <summary>
 /// method to handle animals eating leaves
 /// </summary>
 private void EatSomeLeaves()
 {
     foreach (var animal in spawnedAnimals)
     {
         Herbivore herbivore = animal.GetComponent <Herbivore>();
         Omnivore  omnivore  = animal.GetComponent <Omnivore>();
         if (herbivore != null)
         {
             herbivore.Eat(false);
         }
         if (omnivore != null)
         {
             omnivore.Eat(false);
         }
     }
 }
示例#2
0
 /// <summary>
 /// method to handle animals eating meat
 /// </summary>
 private void EatSomeMeat()
 {
     foreach (var animal in spawnedAnimals)
     {
         // look through the list for carnivores and omnivores
         Carnivore carnivore = animal.GetComponent <Carnivore>();
         Omnivore  omnivore  = animal.GetComponent <Omnivore>();
         // if the animal(s) exist(s), invoke Eat
         if (carnivore != null)
         {
             carnivore.Eat(true);
         }
         if (omnivore != null)
         {
             omnivore.Eat(true);
         }
     }
 }