using UnityEngine;
using System.Collections;

public class EnemyMovement : MonoBehaviour {

	// Physics attributes
	private Vector3 direction;
	private float speed;

	// Object/Script references
	private GameObject player;
	private BoulderMovementScript pScript;

	// Check for collision with player
	void OnCollisionEnter(Collision collision)
	{
		if (collision.gameObject.tag == "Player")
		{
			//Assume only one terrain displayer at a time
			var terrainDisplayer = GameObject.FindObjectOfType(typeof(TerrainDisplayer)) as TerrainDisplayer;        
			if (terrainDisplayer != null && terrainDisplayer.PrefabManager != null && terrainDisplayer.PrefabManager.Pool != null)
			{
				terrainDisplayer.PrefabManager.Pool.Remove(this.gameObject);
			} 

			pScript.enemyKilled = true;
		}
	}

	// Use this for initialization
	void Start () 
	{
		direction = new Vector3 (1.0f, 0.0f, 0.0f);
		speed = 3.0f;

		// Initialise object/script references
		player = GameObject.Find ("Boulder");
		pScript = player.GetComponent<BoulderMovementScript>();
	}
	
	// Update is called once per frame
	void Update () 
	{
		Vector3 movement = new Vector3(
							direction.x * speed,
							direction.y * speed, 
							direction.z * speed);

		// Move sprite
		transform.position += movement*Time.deltaTime;

	}
}
