コード例 #1
0
        void OnTriggerExit(Collider other)
        {
            if (other.isTrigger)
            {
                return;
            }
            var TargetRoot = other.transform.root;

            if (TargetRoot != CurrentAnimal)
            {
                return;                                             //If is another animal exiting the zone SKIP
            }
            if (AlreadyHitted.Find(item => item == other))          //Remove the collider from the list that is exiting the zone.
            {
                AlreadyHitted.Remove(other);
            }


            if (AlreadyHitted.Count == 0)                                        //When all the collides are removed from the list..
            {
                enemy = TargetRoot.GetComponentInChildren <IMDamage>();          //Get the Animal on the Other collider

                if (enemy != null)                                               //if the other does'nt have the animal script skip
                {
                    //  if (self == enemy) return;                                      //Don't Hit yourself
                    EnemyStatExit.ModifyStat(TargetRoot.GetComponentInChildren <Stats>());
                }
                CurrentAnimal = null;
            }
        }
コード例 #2
0
        void OnTriggerEnter(Collider other)
        {
            var Root = other.transform.root;

            if (other.isTrigger && TriggerInteraction == QueryTriggerInteraction.Ignore)
            {
                return;                                                                                                                             //just collapse when is a collider what we are hitting
            }
            if (!MalbersTools.Layer_in_LayerMask(other.gameObject.layer, HitLayer))
            {
                return;                                                                      //Just hit what is on the HitMask Layer
            }
            if (Root == Owner.transform)
            {
                return;                                                                    //Don't hit yourself;
            }
            if (!AlreadyHitted.Find(item => item == Root))                                 //if the entering collider is not already on the list add it
            {
                AlreadyHitted.Add(Root);
            }

            if (Root == CurrentAnimal)
            {
                return;                                                           //if the animal is the same, do nothing we already done the logic below
            }
            else
            {
                if (CurrentAnimal)
                {
                    AlreadyHitted = new List <Transform>();                        //Clean the colliders if you had a previus animal
                }
                CurrentAnimal = Root;                                              //Is a new Animal that is enetering the Attack Trigger

                var TargetPos = Root.position;

                var mesh = Root.GetComponentInChildren <Renderer>();
                if (mesh != null)
                {
                    TargetPos = mesh.bounds.center;                                         //Get the mesh Bounds Center
                }
                Vector3 direction = (Owner.position - TargetPos).normalized;                //Calculate the direction of the attack

                var interactable = other.transform.GetComponent <IInteractable>();          //Get the Animal on the Other collider

                interactable?.Interact();

                enemy = Root.GetComponentInChildren <IMDamage>();                           //Get the Animal on the Other collider

                if (enemy != null)                                                          //if the other does'nt have the Damagable Interface dont send the Damagable stuff
                {
                    enemy.HitDirection = direction;
                    enemy.Damage();
                    EnemyStatEnter.ModifyStat(Root.GetComponentInChildren <Stats>()); //Affect Stats
                }
                else if (other.attachedRigidbody && PushForce != 0)                   //If the other has a riggid body and it can be pushed
                {
                    other.attachedRigidbody.AddForce(-direction * PushForce, ForceMode.VelocityChange);
                }
            }
        }
コード例 #3
0
        void OnDisable()
        {
            if (Trigger)
            {
                Trigger.enabled = false;
            }

            TryDamage(enemy, EnemyStatExit); //Means the Colliders was disable before Exit Trigger
            enemy = null;

            AlreadyHitted = new List <Collider>();
            OnAttackEnd.Invoke();
        }
コード例 #4
0
        void OnEnable()
        {
            if (Owner == null)
            {
                Owner = transform.root.gameObject;                                        //Set which is the owner of this AttackTrigger
            }
            if (Trigger)
            {
                Trigger.enabled = Trigger.isTrigger = true;
            }


            AlreadyHitted = new List <Collider>();
            OnAttackBegin.Invoke();
            enemy = null;
        }
コード例 #5
0
        void OnTriggerExit(Collider other)
        {
            if (IsInvalid(other))
            {
                return;
            }

            if (enemy != other.GetComponentInParent <IMDamage>())
            {
                return;                                                                 //If is another animal exiting the trigger SKIP
            }
            if (AlreadyHitted.Find(col => col == other))                                //Remove the collider from the list that is exiting the zone.
            {
                AlreadyHitted.Remove(other);
            }


            if (AlreadyHitted.Count == 0)        //When all the collides are removed from the list..
            {
                TryDamage(enemy, EnemyStatExit); //if the other does'nt have the Damagable Interface dont send the Damagable stuff
                enemy = null;
            }
        }
コード例 #6
0
        void OnTriggerEnter(Collider other)
        {
            if (IsInvalid(other))
            {
                return;                                                             //Check Layers and Don't hit yourself
            }
            var Newenemy = other.GetComponentInParent <IMDamage>();                 //Get the Animal on the Other collider

            if (!AlreadyHitted.Contains(other))
            {
                AlreadyHitted.Add(other);                                            //if the entering collider is not already on the list add it
            }
            Direction = (Owner.transform.position - other.bounds.center).normalized; //Calculate the direction of the attack

            TryInteract(other.gameObject);                                           //Get the interactable on the Other collider
            TryPhysics(other.attachedRigidbody, other, Direction, Force);            //If the other has a riggid body and it can be pushed

            if (enemy == Newenemy)
            {
                return;                                                                 //if the animal is the same, do nothing we already in one of the Animal Colliders
            }
            else                                                                        //Is a new Animal
            {
                if (enemy != null)
                {
                    AlreadyHitted = new List <Collider>();                              //Clean the colliders if you had a previus animal
                }
                enemy = Newenemy;                                                       //Get the Damager on the Other collider
                // enemyStats = other.GetComponentInParent<Stats>();


                OnHit.Invoke(other.transform);

                TryDamage(enemy, statModifier); //if the other does'nt have the Damagable Interface dont send the Damagable stuff
            }
        }