using UnityEngine;
using UnityEngine.UI;

public class ToolTip : MonoBehaviour {
	public GameObject template; //must contain a Text child
	public Button button;
	public string text;

	private GameObject clone;
	private bool isOver = false;

	void Update() {

		if (isOver) {
			if (!button.interactable) {
				clone.SetActive(true);

				clone.transform.position = Input.mousePosition + new Vector3(5, -5, 0);
				clone.GetComponentInChildren<Text>().text = text;
			}
			else {
				clone.SetActive(false);
			}
		}

	}

	public void mouseEnter() {
		isOver = true;
		if (clone != null) {
			Destroy(clone);
		}
		clone = GameObject.Instantiate(template, GameObject.Find("Canvas").transform);
	}

	public void mouseExit() {
		isOver = false;
		if (clone != null) {
			Destroy(clone);
		}
	}
}
