Пример #1
0
        void OnTriggerExit(Collider other)
        {
            Animal animal = other.GetComponentInParent <Animal>();

            if (!animal)
            {
                return;          //If there's no animal script found skip all
            }
            if (animal != this.animal)
            {
                return;
            }

            if (HeadOnly && !other.name.Contains("Head"))
            {
                return;
            }

            if (_colliders.Find(item => item == other))     //Remove the collider that entered off the list.
            {
                _colliders.Remove(other);
            }

            if (_colliders.Count == 0)
            {
                OnExit.Invoke(animal);                              //Invoke On Exit when all colliders of the animal has exited the Trigger Zone
                animal.OnAction.RemoveListener(OnActionListener);   //Remove the Method fron the Action Listener
                animal.ActionEmotion(-1);                           //Reset the Action ID
                this.animal = null;
            }
        }
Пример #2
0
        void OnTriggerEnter(Collider other)
        {
            Animal animal = other.GetComponentInParent <Animal>();

            if (other.gameObject.layer != 20)
            {
                return;                                                         //Just use the Colliders with the Animal Layer on it
            }
            if (!animal)
            {
                return;                                                         //If there's no animal script found skip all
            }
            if (_colliders == null)
            {
                _colliders = new List <Collider>();                              //Check all the colliders that enters the Action Zone Trigger
            }
            if (HeadOnly && !other.name.ToLower().Contains("head"))
            {
                return;                                                         //If is Head Only and no head was found Skip
            }
            if (_colliders.Find(item => item == other) == null)                 //if the entering collider is not already on the list add it
            {
                _colliders.Add(other);
            }

            if (animal == this.animal)
            {
                return;                                             //if the animal is the same do nothing
            }
            else
            {
                this.animal = animal;
            }

            animal.OnAction.AddListener(OnActionListener);          //Listen when the animal activate the Action Input

            OnEnter.Invoke(animal);
            animal.ActionEmotion(ID);

            if (automatic && animal.CurrentAnimState.IsTag("Locomotion"))       //Just activate when is on the Locomotion State if this is automatic
            {
                animal.EnableAction(true);
                StartCoroutine(ReEnable(animal));
                //this.animal.ActionID = -1;
                //this.animal = null;
                OnActionListener();
            }
        }
Пример #3
0
        /// <summary>
        /// This will disable the Collider on the action zone
        /// </summary>
        /// <param name="animal"></param>
        /// <returns></returns>
        IEnumerator ReEnable(Animal animal) //For Automatic only
        {
            if (AutomaticDisabled > 0)
            {
                GetComponent <Collider>().enabled = false;
                yield return(null);

                yield return(null);

                animal.ActionEmotion(-1);
                yield return(new WaitForSeconds(AutomaticDisabled));

                GetComponent <Collider>().enabled = true;
            }
            this.animal = null;     //Reset animal
            _colliders  = null;     //Reset Colliders
            yield return(null);
        }