using UnityEngine;
using System.Collections;

public class HitAim : MonoBehaviour {
	int func = 0;
	float timer = 0f;
	int funcValue = -1;
	public TweenScale sphere;
	
	public Transform currNpc = null;
	
	public static HitAim instance;
	
	void Awake () {
		instance = this;
		
	}
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (timer > 0f) {
			timer -= Time.deltaTime;
			
			if (timer <=0f){
				ExecAim(func);
				func = 0;
			}
		}
	}
	
	
	
	void OnTriggerEnter(Collider col) {
		print (col.tag);

		if (col.tag == "Npc" && func != 2){
			func = 1;
			timer = 0.2f;
			currNpc = col.transform;
			col.transform.LookAt(Player.instance.transform);
			
		} else if (col.tag == "Dialog"){
			func = 2;			
			timer = 1f;
			funcValue = col.gameObject.GetComponent<ButtonValue>().value;
			sphere.gameObject.SetActive(true);
			sphere.ResetToBeginning();
			sphere.PlayForward();
			
		} else if (col.tag == "Exit"){
			func = 3;			
			timer = 1f;			
			sphere.gameObject.SetActive(true);
			sphere.ResetToBeginning();
			sphere.PlayForward();
			
		} 
	}
		
	void OnTriggerExit(Collider col) {
		print (col.tag);
//		if (col.tag == "Npc"){
//			func = 0;
//			timer = 0f;
//			HudController.instance.HideMenu();
//		}
		sphere.gameObject.SetActive(false);
		timer = 0f;
	}
	
	
	void ExecAim(int option) {
		
	switch(option) {
			case 1:
				HudController.instance.ShowMenu();
			break;
		case 2:			
			HudController.instance.ExecButton(funcValue);
			break;
		
			break;
		case 3:			
			Application.LoadLevel("MainMenu");
			break;
		}
	
	
	
	}
}
