Example #1
0
 private void ReproduceRandomly()
 {
     if (Random.Range(0.0f, 1.0f) > 1.00001f - growthRate)
     {
         reproduction.Reproduce();
     }
 }
Example #2
0
    private void ChooseBehaviour()
    {
        if (GetComponent <SleepingBehaviour>() != null)
        {
            return;
        }

        GameObject danger = locator.LocateByTag("Zombie", dangerRange);

        if (danger != null)
        {
            move.Flee            = true;
            move.TargetTransform = danger.transform;
            eating.Target        = null;
            return;
        }
        move.Flee            = false;
        move.TargetTransform = null;

        if (ShouldReproduce())
        {
            GameObject mate = locator.LocateByTag("Carnivore", reproductionRange);
            if (mate != null)
            {
                reproduce.Reproduce();
                move.TargetTransform = null;
            }
            else
            {
                move.TargetTransform = LocatorBehaviour.GetClosest(transform, carnivores);
            }
        }
        else if (IsHungry())
        {
            GameObject food = locator.LocateByTag("Herbivore", eatRange);
            if (food != null)
            {
                eating.Target        = food.transform;
                move.TargetTransform = null;
            }
            else
            {
                move.TargetTransform = LocatorBehaviour.GetClosest(transform, herbivores);
            }
        }
        else
        {
            GameObject mate = locator.LocateByTag("Carnivore", reproductionRange);
            if (mate == null)
            {
                move.TargetTransform = LocatorBehaviour.GetClosest(transform, carnivores);
            }
        }
    }