Пример #1
0
        void OnTriggerEnter(Collider other)
        {
            if (other.isTrigger)
            {
                return;                                         //just collapse when is a collider what we are hitting
            }
            enemy = other.GetComponentInParent <IMDamagable>(); //Get the Animal on the Other collider

            if (enemy != null)                                  //if the other does'nt have the animal script skip
            {
                if (myAnimal.GetComponent <IMDamagable>() == enemy)
                {
                    return;                                                                  //Don't Hit yourself
                }
                Vector3 direction = myAnimal.transform.position - other.bounds.center;       //Calculate the direction of the attack

                DamageValues DV = new DamageValues(direction, damageMultiplier * (myAnimal ? myAnimal.attackStrength : 1));



                enemy.getDamaged(DV);
            }
            else
            {
                if (other.attachedRigidbody && PushForce != 0)        //If the other has a riggid body and it can be pushed
                {
                    other.attachedRigidbody.AddForce((other.transform.position - transform.position).normalized * PushForce, ForceMode.VelocityChange);
                }
            }
        }
        void OnTriggerEnter(Collider other)
        {
            if (other.transform.root == transform.root)
            {
                return;                                                              //Don't hit yourself
            }
            Vector3 direction = -other.bounds.center + Collider.bounds.center;

            DamageValues DV = new DamageValues(direction, damageMultiplier);

            if (other.isTrigger)
            {
                return;                  // just collapse when is a collider what we are hitting
            }
            IMDamagable Enemy = other.GetComponentInParent <IMDamagable>();

            if (Enemy != null)
            {
                Enemy.getDamaged(DV);
            }
        }