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

public class Enemy : MonoBehaviour {

    public int health;
    public int attackPower;

    private void OnCollisionEnter (Collision collision) {
        if (collision.gameObject.tag == "Player") {
            collision.gameObject.GetComponent<playerctrl>().Damaged(attackPower);
        }
    }

    private void OnTriggerEnter (Collider other) {
        if (other.tag == "sonic") {
            if (other.GetComponent<Sonic>().type == SonicType.Attack) {
                Damaged(Mathf.RoundToInt(other.GetComponent<Sonic>().GetPower()));
            }
        }
    }

    public void Damaged (int value) {
        health -= value;
        UpdateDestroy();
    }

    public void UpdateDestroy () {
        if (health <= 0) {
            Destroy(this.gameObject);
        }
    }

}
