using UnityEngine;
using System.Collections;

public class StoneController : MonoBehaviour {

	public GameObject boia;

	private Rigidbody2D rb;
	private Rigidbody2D rb2;
	private bool touch;

	// Use this for initialization
	void Start () {
		rb = GetComponent<Rigidbody2D> ();
		rb2 = boia.GetComponent<Rigidbody2D> ();
	}
	
	// Update is called once per frame
	void Update () {
		Drop ();
		RestartR ();
		if((Input.GetKeyDown(KeyCode.P))){
			Debug.Log ("P");
			rb2.velocity = new Vector2(0,20);
		}
	}
	void Drop(){
		if (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Began) {
			touch = true;
		} else {
			touch = false;
		}

		if((Input.GetKeyDown(KeyCode.Space) || touch)){
			rb.isKinematic = false;
		}
	}
	void RestartR(){
		if((Input.GetKeyDown(KeyCode.R) && GameManager.instance.loseScreen.activeSelf)){
			GameManager.instance.restartButton.RestartGame ();
		}
	}
	void OnBecameInvisible(){

		StartCoroutine (a ());

	}

	IEnumerator a(){

		yield return new WaitForSeconds (.2f);

		Spawner.instance.PushStone ();
		Destroy (this.gameObject);


	}

}
