using UnityEngine;
using System.Collections;

public class YoyoHit : MonoBehaviour {
    public GameObject explosion;
    private GameManager gameManager;

    void Start() {
        gameManager = FindObjectOfType<GameManager>();
    }

    public void OnCollisionEnter(Collision collision) {
        if (collision.gameObject.tag == "Enemy") {
            Opponent opponent = collision.gameObject.GetComponent<Opponent>();
            opponent.hitPoints -= 1;
            if (opponent.hitPoints <= 0) {
                Instantiate(explosion, collision.gameObject.transform.position, Quaternion.identity);
                Destroy(collision.gameObject);
                GetComponent<AudioSource>().Play();
                StartCoroutine(gameManager.enemyDestroyed());
            }
        } else if (collision.gameObject.tag == "Victim" && GetComponent<YoyoController>().yoyo.activeSelf) {
            Instantiate(explosion, collision.gameObject.transform.position, Quaternion.identity);
            Destroy(collision.gameObject);
            GetComponent<AudioSource>().Play();
        }
    }
}
