using UnityEngine;
using System.Collections;

public class IA : MonoBehaviour {
	NavMeshAgent agent;

	public int nbvie = 3;

	public enum ENNEMI{
		LEGER,
		LOURD
	};
	public ENNEMI ennemi = ENNEMI.LEGER;

	void Start () {
		agent = GetComponent<NavMeshAgent> ();
	}
	
	void Update () {
		agent.SetDestination (GameObject.Find("tower").transform.position);
	}

	void OnCollisionEnter(Collision collision) {
		if (collision.gameObject.name == "tower"){
			if (ennemi==ENNEMI.LEGER){
				Game.instance.nbvie--;
			}
			if(ennemi==ENNEMI.LOURD){
				Game.instance.nbvie-=2;
			}
			Destroy(gameObject);
		}

		if (collision.gameObject.name == "Bullet1(Clone)"){
			Destroy(collision.gameObject);
			nbvie--;
			if (nbvie<=0){
				Game.instance.nbEnnemiTue++;
				Game.instance.compteurpoints++;
				Game.instance.score++;
				Destroy(gameObject);
			}
		}

		if (collision.gameObject.name == "Bullet2(Clone)"){
			Destroy(collision.gameObject);
			nbvie-=2;
			if (nbvie<=0){
				Game.instance.nbEnnemiTue++;
				Game.instance.compteurpoints++;
				Game.instance.score++;
				Destroy(gameObject);
			}
		}
	}
}