Exemple #1
0
        void OnTriggerEnter(Collider other)
        {
            if (other.isTrigger)
            {
                return;
            }

            if (!MalbersTools.CollidersLayer(other, LayerMask.GetMask("Animal")))
            {
                return;                                                                             //Just accept animal layer only
            }
            if (HeadOnly && !other.name.Contains(HeadName))
            {
                return;                                                                             //If is Head Only and no head was found Skip
            }
            MAnimal newAnimal = other.GetComponentInParent <MAnimal>();                             //Get the animal on the entering collider

            if (!newAnimal)
            {
                return;                                                                             //If there's no animal do nothing
            }
            if (animal_Colliders.Find(coll => coll == other) == null)                               //if the entering collider is not already on the list add it
            {
                animal_Colliders.Add(other);
            }

            if (newAnimal == CurrentAnimal)
            {
                return;                                                                //if the animal is the same do nothing (when entering two animals on the same Zone)
            }
            else
            {
                if (CurrentAnimal)
                {
                    animal_Colliders = new List <Collider>();                            //Clean the colliders
                }

                CurrentAnimal = newAnimal;                                             //Set a new Animal
                AnimalStats   = CurrentAnimal.GetComponentInParent <Stats>();
                OnEnter.Invoke();
                ActivateZone();
            }
        }