using UnityEngine;
using System.Collections;

public class AnimationPalanco : MonoBehaviour {

    private string action = "action";
    private Animator animator;
    public bool status = false;
    public bool hover = false;
    public bool solved = false;
    private Vector3 point;
    private Rect t;
    Puzzle1 puzz;

    public string puzzle;
    public int key;

    // Use this for initialization

	void Start () {
        this.animator = this.gameObject.GetComponent<Animator>();
        this.puzz = GameObject.Find(puzzle).GetComponent<Puzzle1>();
    }
	
    public void setAction() {
        if (!status) {
            if (!solved) {
                Debug.Log("Solved!" + key);
                this.puzz.activeListener(key);
                solved = true;
            }
        }

        this.animator.SetTrigger(action);
        this.status = !this.status;
        
    }

    void OnCollisionEnter(Collision other) {
        if (other.gameObject.tag == "Player") {
            Debug.Log("Player is jiar");
            hover = true;
        }


    }

    void OnCollisionExit(Collision other) {
        if (other.gameObject.tag == "Player")
        {
            Debug.Log("Player is not jiar");
            hover = false;
        }
    }

    void OnGUI() {
        if (hover) {
            this.point = Camera.main.WorldToScreenPoint(this.gameObject.transform.position);
            this.t = new Rect(point.x, point.y, 300, 300);
            GUI.Label(this.t, "<size=" + ((50)) + ">" + "PRESS ACTION" + "</size>");
        }
    }
    
}
