using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;

public class BeHitTrigger : MonoBehaviour
{
    public GameObject owner;

    private void Awake()
    {
        if (GetComponentInParent<PlayerController>())
        {
            owner = GetComponentInParent<PlayerController>().gameObject;
        }
        else if (GetComponentInParent<Demonic>())
        {
            owner = GetComponentInParent<Demonic>().gameObject;
        }
        else if (GetComponentInParent<Tower>())
        {
            owner = GetComponentInParent<Tower>().gameObject;
        }
        else if (GetComponentInParent<Enemy>())
        {
            owner = GetComponentInParent<Enemy>().gameObject;
        }
        else if (GetComponentInParent<EnemyTower>())
        {
            owner = GetComponentInParent<EnemyTower>().gameObject;
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        
    }

    public void BeHit(int damage, Vector3 force)
    {
        print("BeHit");
        switch (owner.tag)
        {
            case "Player":
                PlayerController player = owner.GetComponent<PlayerController>();
                player.BeHit(damage, force);
                break;
            case "Demonic":
                Demonic demonic = owner.GetComponent<Demonic>();
                demonic.BeHit(damage, force);
                break;
            case "Tower":
                Tower tower = owner.GetComponent<Tower>();
                tower.BeHit(damage, force);
                break;
            case "Enemy":
                Enemy enemy = owner.GetComponent<Enemy>();
                enemy.BeHit(damage, force);
                break;
            case "EnemyTower":
                EnemyTower enemyTower = owner.GetComponent<EnemyTower>();
                enemyTower.BeHit(damage, force);
                break;
            default:
                break;
        }
    }
}
