// Use this for initialization
 void Start()
 {
     coinTotalManager = GameObject.Find("Coin Handler").GetComponent <CoinTotalManager> ();
     currentStates    = GameObject.Find("Power Up Button(Clone)").GetComponent <PowerButtonCurrentStates> ();
     if (currentStates.GetPlusFivePowerPressed())
     {
         float totalCircleAngle       = Mathf.Rad2Deg * (2 * (Mathf.Atan(((transform.position.x) / (transform.position.x * .8930232558f)))));
         float incrementalCircleAngle = totalCircleAngle / 6;
         instantiatedPressedPlusFivePowerButton = (GameObject)Instantiate(pressedPlusFivePowerButton, new Vector3(transform.position.x, transform.position.y, transform.position.z - 1), Quaternion.identity);
         instantiatedPressedPlusFivePowerButton.transform.Rotate(new Vector3(0, 0, incrementalCircleAngle));
         instantiatedPressedPlusFivePowerButton.transform.parent = transform;
     }
     incrementalAngle          = GameObject.Find("Power Up Button(Clone)").GetComponent <PowerButtonHandler> ().GetIncrementalCircleAngle();
     circleObject              = GameObject.Find("Plus Five Circle");
     touchOn                   = true;
     soundHandler              = GameObject.Find("Game Manager").GetComponent <SoundHandler> ();
     touchHandler              = GameObject.Find("Level Controller").GetComponent <RockLevelTouchHandler> ();
     powerPercentageController = GameObject.Find("Level Controller").GetComponent <PowerPercentageController> ();
 }
    // Update is called once per frame
    void Update()
    {
        if (numbersInstantiated && instantiatedCoinNumberOne == null && instantiatedCoinNumberTwo == null && instantiatedCoinNumberThree == null)
        {
            numbersInstantiated = false;
        }
        if (!goHome && !numbersInstantiated && !currentStates.GetPlusFivePowerPressed() && Mathf.Abs(Mathf.Abs((circleObject.transform.rotation.eulerAngles.z) - (360 - (incrementalAngle)))) < 4f)
        {
            instantiatedThousanthCoin = (GameObject)Instantiate(coinNumberFive, new Vector3(targetX, targetY, -1), Quaternion.Euler(new Vector3(0, 0, 22.5f)));
            PowerButtonHandler.increaseCoinNumber();
            instantiatedCoinNumberOne = (GameObject)Instantiate(coinNumberZero, new Vector3(targetX, targetY, -1), Quaternion.identity);
            PowerButtonHandler.increaseCoinNumber();
            instantiatedCoinNumberTwo = (GameObject)Instantiate(coinNumberZero, new Vector3(targetX, targetY, -1), Quaternion.Euler(new Vector3(0, 0, -22.5f)));
            PowerButtonHandler.increaseCoinNumber();
            instantiatedCoinNumberThree = (GameObject)Instantiate(coinNumberZero, new Vector3(targetX, targetY, -1), Quaternion.Euler(new Vector3(0, 0, -45)));
            PowerButtonHandler.increaseCoinNumber();
            if (GameObject.Find("Plus Five Coin Holder") != null)
            {
                coinNumberParent = GameObject.Find("Plus Five Coin Holder");
            }
            else
            {
                coinNumberParent = new GameObject();
                coinNumberParent.transform.position = new Vector3(targetX, transform.position.y, transform.position.z);
                coinNumberParent.name = "Plus Five Coin Holder";
            }
            instantiatedThousanthCoin.transform.parent   = coinNumberParent.transform;
            instantiatedCoinNumberOne.transform.parent   = coinNumberParent.transform;
            instantiatedCoinNumberTwo.transform.parent   = coinNumberParent.transform;
            instantiatedCoinNumberThree.transform.parent = coinNumberParent.transform;

            instantiatedThousanthCoin.name   = "Thousanth Power Coin";
            instantiatedCoinNumberOne.name   = "Power Coin One";
            instantiatedCoinNumberTwo.name   = "Power Coin Two";
            instantiatedCoinNumberThree.name = "Power Coin Three";

            instantiatedThousanthCoin.GetComponent <PowerCoinNumberMovementController> ().SetAttachedButton(gameObject);
            instantiatedCoinNumberOne.GetComponent <PowerCoinNumberMovementController> ().SetAttachedButton(gameObject);
            instantiatedCoinNumberTwo.GetComponent <PowerCoinNumberMovementController> ().SetAttachedButton(gameObject);
            instantiatedCoinNumberThree.GetComponent <PowerCoinNumberMovementController> ().SetAttachedButton(gameObject);
            numbersInstantiated = true;
            numbersSentHome     = false;
        }
        if (goHome && numbersInstantiated && !numbersSentHome)
        {
            instantiatedThousanthCoin.GetComponent <PowerCoinNumberMovementController> ().MoveNumberBack(true);
            instantiatedCoinNumberOne.GetComponent <PowerCoinNumberMovementController> ().MoveNumberBack(true);
            instantiatedCoinNumberTwo.GetComponent <PowerCoinNumberMovementController> ().MoveNumberBack(true);
            instantiatedCoinNumberThree.GetComponent <PowerCoinNumberMovementController> ().MoveNumberBack(true);
            numbersSentHome = true;
        }

        if (goHome && PowerButtonHandler.GetCoinNumberCount() == 0)
        {
            circleObject.transform.rotation = Quaternion.Slerp(circleObject.transform.rotation, Quaternion.Euler(0, 0, 0), Time.deltaTime * 8f);
        }
        else if (!goHome)
        {
            circleObject.transform.rotation = Quaternion.Slerp(circleObject.transform.rotation, Quaternion.Euler(0, 0, -incrementalAngle), Time.deltaTime * 8f);
        }

        if (goHome && Mathf.Abs((circleObject.transform.rotation.eulerAngles.z) - ((0))) < .1f)
        {
            Destroy(circleObject);
            Destroy(gameObject);
        }

        if (!currentStates.GetPlusFivePowerPressed() && touchOn && touchHandler.GetGameStarted())
        {
            if (Input.GetMouseButtonDown(0))
            {
                CheckTouch(Input.mousePosition);
            }

            if (Input.GetMouseButton(0))
            {
                CheckTouch2(Input.mousePosition);
            }

            if (Input.GetMouseButtonUp(0))
            {
                //				if (instantiatedPressedPlusFivePowerButton != null)
                //					Destroy (instantiatedPressedPlusFivePowerButton);
                CheckTouch3(Input.mousePosition);
            }
        }

        if (rotateNumbers)
        {
            coinNumberParent.transform.Rotate(new Vector3(0, 0, -180) * Time.deltaTime * 2);
            if (instantiatedCoinNumberOne == null && instantiatedCoinNumberTwo == null && instantiatedCoinNumberThree == null)
            {
                Destroy(coinNumberParent);
                rotateNumbers = false;
            }
        }
    }