/// <summary>
 /// Check collision and apply damage if other object is enemy
 /// </summary>
 /// <param name="other"></param>
 public void OnTriggerEnter(Collider other)
 {
     if (alive)
     {
         TriggerSender ts = other.GetComponent <TriggerSender>();
         if (ts != null)
         {
             GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
             IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
             if (damagable != null)
             {
                 if ((damagable.GetFaction() & oppositeFaction) != 0)
                 {
                     if (damagable.RecieveAttack(gameObject, other, attackDamage, dir, attackForce))
                     {
                         SoundManager.GetInstance().Play(destructionClip);
                         Clear();
                     }
                 }
             }
         }
         else
         {
             if (other.CompareTag("Enviorment"))
             {
                 SoundManager.GetInstance().Play(destructionClip);
                 Clear();
             }
         }
     }
 }
示例#2
0
 /// <summary>
 /// Apply damage to player if self attackHitbox collides with it.
 /// </summary>
 /// <param name="origin">GameObject on which OnTriggerExit method was called.</param>
 /// <param name="other">Collider data of the OnTriggerExit method.</param>
 public void OnExtensionTriggerEnter(GameObject origin, Collider other)
 {
     if (origin == attackHitbox)
     {
         TriggerSender ts = other.GetComponent <TriggerSender>();
         if (ts != null)
         {
             GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
             IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
             if (damagable != null)
             {
                 if ((damagable.GetFaction() & oppositeFaction) != 0)
                 {
                     damagable.RecieveAttack(origin, other, stats.attackDamageMultiplier, lookingDirection, stats.attackForceMultiplier);
                 }
             }
         }
     }
 }
示例#3
0
    /// <summary>
    /// Apply damage to player if the attack hitbox of any of the body trails collides with it.
    /// </summary>
    /// <param name="origin">GameObject on which OnTriggerExit method was called.</param>
    /// <param name="other">Collider data of the OnTriggerExit method.</param>
    public void OnExtensionTriggerEnter(GameObject origin, Collider other)
    {
        if (alive)
        {
            bool attackCollision = false;
            if (origin == attackHitbox)
            {
                attackCollision = true;
            }
            for (int i = 0; i < trailSections.Length; i++)
            {
                if (origin == trailSections[i].gameObject)
                {
                    attackCollision = true;
                    break;
                }
            }

            if (attackCollision)
            {
                TriggerSender ts = other.GetComponent <TriggerSender>();
                if (ts != null)
                {
                    GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
                    IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        if ((damagable.GetFaction() & oppositeFaction) != 0)
                        {
                            damagable.RecieveAttack(origin, other, stats.attackDamageMultiplier, Tools.Vector3ToDir4Int(other.transform.position - origin.transform.position), stats.attackForceMultiplier);
                        }
                    }
                }
            }
        }
    }
示例#4
0
    /// <summary>
    /// Check the colisions of the bodyHitbox and attackHitobx, and respond acordingly.
    /// </summary>
    /// <param name="origin"></param>
    /// <param name="other"></param>
    public void OnExtensionTriggerEnter(GameObject origin, Collider other)
    {
        if (isActive && isAlive && !isDespawning)
        {
            // Check attack
            if (attackCheck && origin == attackHitbox)
            {
                TriggerSender ts = other.GetComponent <TriggerSender>();
                if (ts != null)
                {
                    // Attacking enemy entities
                    GameObject triggerReciever = ts.GetReciever().GetRecieverGameObject();
                    IDamagable damagable       = triggerReciever.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        // Apply damage
                        if (!attackWhitelist.Contains(triggerReciever))
                        {
                            if ((damagable.GetFaction() & oppositeFaction) != 0)
                            {
                                bool recieved = damagable.RecieveAttack(origin, other, attackDamage, facingDirection, pushForce, stunForce);
                                if (recieved)
                                {
                                    attackWhitelist.Add(triggerReciever);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Attacking destructible enviorment.
                    IDamagable damagable = other.GetComponent <IDamagable>();
                    if (damagable != null)
                    {
                        if (!attackWhitelist.Contains(other.gameObject))
                        {
                            if ((damagable.GetFaction() & oppositeFaction) != 0)
                            {
                                bool recieved = damagable.RecieveAttack(origin, other, attackDamage, facingDirection, pushForce, stunForce);
                                if (recieved)
                                {
                                    attackWhitelist.Add(other.gameObject);
                                }
                            }
                        }
                    }
                }
            }

            // Check other collisions
            if (origin == bodyHitbox)
            {
                // Pickups
                if (other.CompareTag("Collectible"))
                {
                    other.GetComponent <ICollectible>().Collect();
                }

                // Level end
                if (other.CompareTag("Endpoint"))
                {
                    if (other.GetComponent <EndpointController>().GoNextLevel())
                    {
                        despawnPosition = other.transform.position;
                        animator.SetTrigger("Despawn");
                        isDespawning = true;
                    }
                }
            }
        }
    }