Example #1
0
    private void OnTriggerEnterEvent(Collider2D col)
    {
        if (col.gameObject.CompareTag("Item"))
        {
            InteractableItem item = col.gameObject.GetComponent <InteractableItem>();

            if (item != null)
            {
                item.HandleItem();
            }
        }

        else if (col.gameObject.CompareTag("Laser"))
        {
            Vector2 direction = transform.position - col.transform.position;
            Knockback(direction, knockbackDuration, knockbackDecreaseOverTime, true);
            player.TakeDamage(2f);
        }

        else if (col.gameObject.CompareTag("Platform"))
        {
            transform.parent = col.transform;
        }

        else if (col.gameObject.CompareTag("Enemy"))
        {
            Vector2 direction = transform.position - col.transform.position;
            Knockback(direction, knockbackDuration, knockbackDecreaseOverTime, true);
            player.TakeDamage(2f);
        }

        else if (col.gameObject.CompareTag("Bullet"))
        {
            Vector2 direction = transform.position - col.transform.position;
            Knockback(direction, knockbackDuration, knockbackDecreaseOverTime, true);
            player.TakeDamage(1f);
            Destroy(col.gameObject);
        }

        else if (col.gameObject.CompareTag("EnemyHead"))
        {
            Knockback(Vector2.up, 0.7f, knockbackDecreaseOverTime, false);
            BaseEnemy enemyHit = col.gameObject.GetComponentInParent <BaseEnemy>();
            enemyHit.Kill();
        }
    }