Example #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject collidedObject = collision.gameObject;

        if (collidedObject.GetComponent <Character2D>() && collidedObject.layer != layerToIgnore && !hitCharacters.Contains(collidedObject) && collidedObject.layer != 13)
        {
            if (collidedObject.GetComponent <AI>())
            {
                if (!collidedObject.GetComponent <AI>().isDead)
                {
                    hitCharacters.Add(collidedObject);
                    Character2D characterHit = collidedObject.GetComponent <Character2D>();
                    characterHit.TakeDamage(Damage);
                    characterHit.Knockback(new Vector2(KnockbackDirection.x, 0.5f), KnockbackPower, KnockbackDuration);
                }
            }
            else
            {
                hitCharacters.Add(collidedObject);
                Character2D characterHit = collidedObject.GetComponent <Character2D>();
                characterHit.TakeDamage(Damage);
                characterHit.Knockback(new Vector2(KnockbackDirection.x, 0.5f), KnockbackPower, KnockbackDuration);
            }
        }
    }
Example #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject collidedObject = collision.gameObject;

        if (collidedObject.GetComponent <Character2D>() && collidedObject.layer != 13)
        {
            Character2D character = collidedObject.GetComponent <Character2D>();
            character.TakeDamage(damage);
            character.Knockback(new Vector2(-character.XMovementDirection.x, 1), 10, 1f);
        }
    }