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

public class Hologram : MonoBehaviour {

	GameObject player;
	GameObject scripts;

	//Movement
	float localX;
	float localZ;

	//Layers
	string topLayer;
	Dictionary<string, GameObject> layers = new Dictionary<string, GameObject>();

	// Use this for initialization
	void Start () {
		player = GameObject.Find ("Player");
		scripts = GameObject.Find("ScriptContainer");

		layers.Add ("red", GameObject.Find ("RedLayer"));
		layers.Add ("blue", GameObject.Find ("BlueLayer"));
		layers.Add ("green", GameObject.Find ("GreenLayer"));
		layers.Add ("yellow", GameObject.Find ("YellowLayer"));
	}
	
	// Update is called once per frame
	void Update () {

		//Animate
		string trigger = player.GetComponent<PlayerMovement>().getAnimTrigger();
		if(!GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName(trigger) || !player.GetComponent<PlayerMovement>().isMoving()){
			GetComponent<Animator>().SetTrigger(trigger);
		}

		topLayer = scripts.GetComponent<LayerManager>().getTopLayerName();

		move ();

		//Hide me if the player is on the top
		if(player.GetComponent<PlayerMovement>().getLayerName() == topLayer){
			renderer.enabled = false;
		}
		else{
			renderer.enabled = true;
		}
	}

	void move(){
		transform.position = new Vector3(layers[topLayer].transform.position.x + player.GetComponent<PlayerMovement>().getLocalX(),
		                                 layers[topLayer].transform.position.y,
		                                 layers[topLayer].transform.position.z + player.GetComponent<PlayerMovement>().getLocalZ());
	}
}
