Пример #1
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);
            }
        }
    }
Пример #2
0
 private void OnEnable()
 {
     age        = GetComponent <AgingBehaviour>();
     hunger     = GetComponent <HungerBehaviour>();
     move       = GetComponent <MovingBehaviour>();
     locator    = GetComponent <LocatorBehaviour>();
     reproduce  = GetComponent <ReproductionBehaviour>();
     herbivores = GameObject.FindGameObjectWithTag("HerbivoreContainer").transform;
     eating     = GetComponent <EatingBehaviour>();
     carnivores = GameObject.FindGameObjectWithTag("CarnivoreContainer").transform;
 }
Пример #3
0
    public void TurnIntoZombie()
    {
        if (isZombie)
        {
            return;
        }

        isZombie = true;
        tag      = "Zombie";
        if (DiseaseEffect != null)
        {
            Destroy(DiseaseEffect);
        }

        HerbivoreBehaviour herbivore = GetComponent <HerbivoreBehaviour>();

        if (herbivore != null)
        {
            Destroy(herbivore);
        }
        age = GetComponent <AgingBehaviour>();
        if (age != null)
        {
            Destroy(age);
        }
        hunger = GetComponent <HungerBehaviour>();
        hunger.HungerDamage = 0;
        reproduce           = GetComponent <ReproductionBehaviour>();
        if (reproduce != null)
        {
            Destroy(reproduce);
        }

        locator    = GetComponent <LocatorBehaviour>();
        eating     = GetComponent <EatingBehaviour>();
        carnivores = GameObject.FindGameObjectWithTag("CarnivoreContainer").transform;

        move       = GetComponent <MovingBehaviour>();
        move.Speed = ZombieSpeed;
        move.Flee  = false;

        transform.parent = GameObject.FindGameObjectWithTag("ZombieContainer").transform;

        GetComponent <Animator>().runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("Animations/Zombie/ZombieSheet_0");
    }
Пример #4
0
    private void ChooseBehaviour()
    {
        if (!isZombie)
        {
            return;
        }

        if (GetComponent <SleepingBehaviour>() != null)
        {
            return;
        }

        GameObject target = locator.LocateByTag("Carnivore", eatRange);

        if (target != null)
        {
            eating.Target = target.transform;
        }
        else
        {
            move.TargetTransform = LocatorBehaviour.GetClosest(transform, carnivores);
        }
    }