using UnityEngine;
using System.Collections;

public class Monster : MonoBehaviour {
    private Transform player;
    public float movementSpeed;

    public int damageDone;
	public bool dieNextTick = false;

	private ArduinoHandler arduinoHandler;

    public MonsterSpawner spawner;
	// Use this for initialization
	void Start () {
        movementSpeed = 1f;
        player = GameObject.FindGameObjectWithTag("Player").transform;
		arduinoHandler = GameObject.FindGameObjectWithTag("ArduinoHandler").GetComponent<ArduinoHandler>();
		
        damageDone = 1;
	}
	
	// Update is called once per frame
	void Update () {
        //transform.Translate(new Vector3(1, 1, 1));
		
		if(dieNextTick == true) {
			
			Kill();
			return;
		}

        transform.Translate((player.position - transform.position).normalized * movementSpeed * Time.deltaTime);
	}

    public void Kill()
    {
		//if (player.health > 0) {
			
			//arduinoHandler.MonsterKilled();
			spawner.monsters.Remove(this);
			gameObject.active = false;
			Destroy(gameObject);
		//}
    }
}
