using UnityEngine;
using System.Collections;

public class triggerTrap : MonoBehaviour {
	private bool used = false;
	public GameObject trap;
	void OnTriggerStay(Collider other){
		if (other.tag == "player1Hand" && (this.tag == "paka" || this.tag == "objective")) {
			float click = Input.GetAxis("Fire1");
			if(click > 0 && !used){
				used = true;
				this.trigger ();
			}
		}
		if (other.tag == "player2Hand" && (this.tag == "paka" || this.tag == "objective")) {
			float click = Input.GetAxis("Fire2");
			if(click > 0 && !used){
				used = true;
				this.trigger ();
			}
		}
	}
	private void trigger(){
		Debug.Log ("pada");	
		if (trap != null) {
			trap.gameObject.SetActive(true);
			if (trap.tag == "mriz") {
				Transform child = trap.transform.GetChild(1);
				StartCoroutine(close (child));
				trap.animation.Play ("akce");
			}
		}
	}
	private IEnumerator close(Transform child){
		yield return new WaitForSeconds (2f);
		child.GetComponent<BoxCollider>().collider.enabled = true;
	}
}
