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

public class TriangleEnemy : MonoBehaviour {

	//Movement
	float moveSpeed = .01f;

	//Color vars
	string myColor;

	//Player
	GameObject player;

	//Damage
	int damage = 14;
	
	// Use this for initialization
	void Start () {
		//Find the player to chase him
		player = GameObject.Find ("Player");
	}
	
	// Update is called once per frame
	void Update () {
		//Set damage amount
		GetComponent<Enemy>().damageAmount = damage;

		//Move enemy on plane
		Vector3 playerPosition = new Vector3(GetComponent<Enemy>().layers[GetComponent<Enemy>().layerName].transform.position.x + player.GetComponent<PlayerMovement>().getLocalX(),
		                                     GetComponent<Enemy>().layers[GetComponent<Enemy>().layerName].transform.position.y,
		                                     GetComponent<Enemy>().layers[GetComponent<Enemy>().layerName].transform.position.z + player.GetComponent<PlayerMovement>().getLocalZ());
		Vector3 toPlayer = playerPosition - transform.position;
		toPlayer.Normalize();
		GetComponent<Enemy>().localX += toPlayer.x * moveSpeed;
		GetComponent<Enemy>().localZ += toPlayer.z * moveSpeed;
		
		//Move based on the layer's position and local position
		transform.position = new Vector3(GetComponent<Enemy>().layers[GetComponent<Enemy>().layerName].transform.position.x + GetComponent<Enemy>().localX,
		                                 GetComponent<Enemy>().layers[GetComponent<Enemy>().layerName].transform.position.y,
		                                 GetComponent<Enemy>().layers[GetComponent<Enemy>().layerName].transform.position.z + GetComponent<Enemy>().localZ);
		
	}
}
