using UnityEngine;
using System.Collections;

public class BaseEnemy : MonoBehaviour 
{
	public int health = 10;
	public int speed = 3;
	public int damage = 5;
	public int duration = 10;
	public GameObject deathSpawn;
	public bool doesElementalDamage;
	public Element.Component elementComponent;
    public bool moveHorizontal = false;

	void Start () 
	{
		Destroy(gameObject,duration);
	}

	void Update () 
	{
        if(moveHorizontal)
        {
            transform.Translate(Vector3.right * speed * Time.deltaTime);
        }
        else
        {
            transform.Translate(Vector3.up * speed * Time.deltaTime);
        }
	}

	public void TakeDamage(int damage)
	{
		health -= damage;
		if(health <= 0)
		{
			Debug.Log("Enemy: Dead");
			if(deathSpawn != null)
				Instantiate(deathSpawn, transform.position, transform.rotation);
			Destroy(gameObject);
		}
	}
	void OnTriggerEnter(Collider damageCheck)
	{
		if(damageCheck.gameObject.GetComponent<Projectile>() != null)
		{
			Debug.Log("Enemy: Damage Taken");
			TakeDamage(damageCheck.gameObject.GetComponent<Projectile>().damage);
			Destroy(damageCheck.gameObject);
		}
	}
}
