using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Spinner2 : MonoBehaviour {
	
	float rotationPerMinute;
	GameObject Scoretext;
	Quoter quoteRef;
	bool resultGlobal;
	
	
	// Use this for initialization
	void Start () {
		Scoretext = GameObject.Find("ScoreGUIText");
		quoteRef = Scoretext.GetComponent <Quoter>();
		//resultGlobal = quoteRef.Finished();
		
		//		print ("count = " + quoteRef.count);
		
		rotationPerMinute = 60.0F;
	}

	public void MoveUp(int val){
		if (val > 11 && val < 19)
		{
			gameObject.transform.Translate(Vector3.up);	
		}
	}

	// Update is called once per frame
	void Update () {
		
		if (CheckGameFinished()){
			StartSpinning();
		}
	}
	
	bool CheckGameFinished(){
		bool result = false;
		
		result = (GameObject.Find("Quote").GetComponent <Quoter> ().finished);
		//result = quoteRef.Finished();
		//result = Quoter.GetComponent <Quoter> ().finished;
		/*try {
			GameObject Quoter = GameObject.Find("ScoreGUIText");
			//result = GameObject.Find("ScoreGUIText").GetComponent <Quoter>().finished;
		} catch (UnityException e){
			result = false;
		} finally {
			print ("Exception");
//			result = GameObject.Find("ScoreGUIText").GetComponent <Quoter>().finished;
		}*/
		return (result);
		
		/*		bool result = GameObject.Find("ScoreGUIText").GetComponent <Quoter>().finished;
		return (result); */
	}
	
	void StartSpinning() {
		print ("start spinning");
		//gameObject.transform.Rotate(0,0,rotationPerMinute*Time.deltaTime);
		
		gameObject.transform.Rotate(0,0,10*rotationPerMinute*Time.deltaTime);
	}
	
	void OnMouseDown() {
		/*		if (GameObject.Find("Quote").GetComponent <Quoter> ().finished)
		{
			StartSpinning();
		}*/
	}
}
