void Start()
    {
        Instance = this;
        if (!PlayerPrefs.HasKey(SAVE_NAME))
        {
            PlayerPrefs.SetString(SAVE_NAME, string.Empty);
        }
        if (!PlayerPrefs.HasKey("IsFirstTime"))
        {
            PlayerPrefs.SetInt("IsFirstTime", 1);
        }

        if (PlayerPrefs.GetInt("IsFirstTime") == 1)
        {
            PlayerPrefs.SetInt("IsFirstTime", 0);
            CloudVariables.SetImportantValues(0, 1);
            CloudVariables.SetImportantValues(1, 0);
        }

        LoadLocal();

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().EnableSavedGames().Build();

        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.Activate();

        SignIn();
    }
 public void soundButtonClick()
 {
     if (CloudVariables.ImportantValues[0] == 1)
     {
         AudioListener.volume = 0.0f;
         soundoffmenu.GetComponent <Text> ().enabled = true;
         soundonmenu.GetComponent <Text> ().enabled  = false;
         soundoff.GetComponent <Text> ().enabled     = true;
         soundon.GetComponent <Text> ().enabled      = false;
         if (menuUi.activeSelf)
         {
             menuUi.GetComponent <Animator> ().Play("SoundOff", -1, 0f);
         }
         if (gameUi.activeSelf)
         {
             gameUi.GetComponent <Animator> ().Play("SoundOffGame", -1, 0f);
         }
         CloudVariables.SetImportantValues(0, 0);
         PlayGamesScript.Instance.SaveData();
     }
     else if (CloudVariables.ImportantValues[0] == 0)
     {
         AudioListener.volume = 1.0f;
         soundoffmenu.GetComponent <Text> ().enabled = false;
         soundonmenu.GetComponent <Text> ().enabled  = true;
         soundoff.GetComponent <Text> ().enabled     = false;
         soundon.GetComponent <Text> ().enabled      = true;
         if (menuUi.activeSelf)
         {
             menuUi.GetComponent <Animator> ().Play("SoundOn", -1, 0f);
         }
         if (gameUi.activeSelf)
         {
             gameUi.GetComponent <Animator> ().Play("SoundOnGame", -1, 0f);
         }
         CloudVariables.SetImportantValues(0, 1);
         PlayGamesScript.Instance.SaveData();
     }
 }
    void Update()
    {
        if (fpsCounterGo.activeSelf)
        {
            deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
            float fps = 1.0f / deltaTime;
            fpsCounter.text = Mathf.FloorToInt(fps).ToString();
        }

        if (controlGame)
        {
            if (sectionCount == 0)
            {
                lifepoints = 3;
                life.text  = lifepoints.ToString() + " life points left";

                /*
                 *      //default visibility sections
                 *      leftsection11.SetActive (false);
                 *      rightsection11.SetActive (false);
                 *      leftsection21.SetActive (false);
                 *      rightsection21.SetActive (false);
                 *      leftsection22.SetActive (false);
                 *      rightsection22.SetActive (false);
                 *      leftsection41.SetActive (false);
                 *      rightsection41.SetActive (false);
                 *      leftsection42.SetActive (false);
                 *      rightsection42.SetActive (false);
                 *      leftsection43.SetActive (false);
                 *      rightsection43.SetActive (false);
                 *      leftsection44.SetActive (false);
                 *      rightsection44.SetActive (false);
                 */

                //default visibility ui elements
                leftbutton1.enabled = false;
                leftbutton1.GetComponentInChildren <Text> ().enabled = false;
                rightbutton1.enabled = false;
                rightbutton1.GetComponentInChildren <Text> ().enabled = false;
                leftbutton2.enabled = false;
                leftbutton2.GetComponentInChildren <Text> ().enabled = false;
                rightbutton2.enabled = false;
                rightbutton2.GetComponentInChildren <Text> ().enabled = false;
                leftbutton3.enabled = false;
                leftbutton3.GetComponentInChildren <Text> ().enabled = false;
                rightbutton3.enabled = false;
                rightbutton3.GetComponentInChildren <Text> ().enabled = false;
                leftbutton4.enabled = false;
                leftbutton4.GetComponentInChildren <Text> ().enabled = false;
                rightbutton4.enabled = false;
                rightbutton4.GetComponentInChildren <Text> ().enabled = false;
            }
            else if (sectionCount == 1)
            {
                leftsection11.SetActive(true);
                rightsection11.SetActive(true);
                leftsection21.SetActive(false);
                rightsection21.SetActive(false);
                leftsection22.SetActive(false);
                rightsection22.SetActive(false);
                leftsection41.SetActive(false);
                rightsection41.SetActive(false);
                leftsection42.SetActive(false);
                rightsection42.SetActive(false);
                leftsection43.SetActive(false);
                rightsection43.SetActive(false);
                leftsection44.SetActive(false);
                rightsection44.SetActive(false);

                leftbutton1.enabled = false;
                leftbutton1.GetComponentInChildren <Text> ().enabled = false;
                rightbutton1.enabled = false;
                rightbutton1.GetComponentInChildren <Text> ().enabled = false;
                leftbutton2.enabled = false;
                leftbutton2.GetComponentInChildren <Text> ().enabled = false;
                rightbutton2.enabled = false;
                rightbutton2.GetComponentInChildren <Text> ().enabled = false;
                leftbutton3.enabled = false;
                leftbutton3.GetComponentInChildren <Text> ().enabled = false;
                rightbutton3.enabled = false;
                rightbutton3.GetComponentInChildren <Text> ().enabled = false;
                leftbutton4.enabled = false;
                leftbutton4.GetComponentInChildren <Text> ().enabled = false;
                rightbutton4.enabled = false;
                rightbutton4.GetComponentInChildren <Text> ().enabled = false;
            }
            else if (sectionCount == 2)
            {
                leftsection11.SetActive(false);
                rightsection11.SetActive(false);
                leftsection21.SetActive(true);
                rightsection21.SetActive(true);
                leftsection22.SetActive(true);
                rightsection22.SetActive(true);
                leftsection41.SetActive(false);
                rightsection41.SetActive(false);
                leftsection42.SetActive(false);
                rightsection42.SetActive(false);
                leftsection43.SetActive(false);
                rightsection43.SetActive(false);
                leftsection44.SetActive(false);
                rightsection44.SetActive(false);

                leftbutton.GetComponent <Button> ().interactable  = false;
                rightbutton.GetComponent <Button> ().interactable = false;

                leftbutton1.enabled = true;
                leftbutton1.GetComponentInChildren <Text> ().enabled = true;
                rightbutton1.enabled = true;
                rightbutton1.GetComponentInChildren <Text> ().enabled = true;
                leftbutton2.enabled = true;
                leftbutton2.GetComponentInChildren <Text> ().enabled = true;
                rightbutton2.enabled = true;
                rightbutton2.GetComponentInChildren <Text> ().enabled = true;
                leftbutton3.enabled = false;
                leftbutton3.GetComponentInChildren <Text> ().enabled = false;
                rightbutton3.enabled = false;
                rightbutton3.GetComponentInChildren <Text> ().enabled = false;
                leftbutton4.enabled = false;
                leftbutton4.GetComponentInChildren <Text> ().enabled = false;
                rightbutton4.enabled = false;
                rightbutton4.GetComponentInChildren <Text> ().enabled = false;
            }
            else if (sectionCount == 4)
            {
                leftsection11.SetActive(false);
                rightsection11.SetActive(false);
                leftsection21.SetActive(false);
                rightsection21.SetActive(false);
                leftsection22.SetActive(false);
                rightsection22.SetActive(false);
                leftsection41.SetActive(true);
                rightsection41.SetActive(true);
                leftsection42.SetActive(true);
                rightsection42.SetActive(true);
                leftsection43.SetActive(true);
                rightsection43.SetActive(true);
                leftsection44.SetActive(true);
                rightsection44.SetActive(true);

                leftbutton.GetComponent <Button> ().interactable  = false;
                rightbutton.GetComponent <Button> ().interactable = false;

                leftbutton1.enabled = true;
                leftbutton1.GetComponentInChildren <Text> ().enabled = true;
                rightbutton1.enabled = true;
                rightbutton1.GetComponentInChildren <Text> ().enabled = true;
                leftbutton2.enabled = true;
                leftbutton2.GetComponentInChildren <Text> ().enabled = true;
                rightbutton2.enabled = true;
                rightbutton2.GetComponentInChildren <Text> ().enabled = true;
                leftbutton3.enabled = true;
                leftbutton3.GetComponentInChildren <Text> ().enabled = true;
                rightbutton3.enabled = true;
                rightbutton3.GetComponentInChildren <Text> ().enabled = true;
                leftbutton4.enabled = true;
                leftbutton4.GetComponentInChildren <Text> ().enabled = true;
                rightbutton4.enabled = true;
                rightbutton4.GetComponentInChildren <Text> ().enabled = true;
            }
            controlGame = false;
        }

        if (controlScore)
        {
            sections.GetComponent <Animator> ().Play("SectionOn", -1, 0f);
            gameUi.GetComponent <Animator> ().Play("GetScore", -1, 0f);

            if (scoreInt < 10)
            {
                targetPoint.text = "Next Target Point: 10";
            }
            else if (scoreInt < 25)
            {
                targetPoint.text = "Next Target Point: 25";
            }
            else if (scoreInt < 50)
            {
                targetPoint.text = "Next Target Point: 50";
            }
            else if (scoreInt < 100)
            {
                targetPoint.text = "Next Target Point: 100";
            }
            else if (scoreInt < 150)
            {
                targetPoint.text = "Next Target Point: 150";
            }
            else if (scoreInt < 200)
            {
                targetPoint.text = "Next Target Point: 200";
            }
            else if (scoreInt < 250)
            {
                targetPoint.text = "Next Target Point: 250";
            }
            else if (scoreInt < 500)
            {
                targetPoint.text = "Next Target Point: 500";
            }
            else if (scoreInt < 750)
            {
                targetPoint.text = "Next Target Point: 750";
            }
            else if (scoreInt < 1000)
            {
                targetPoint.text = "Next Target Point: 1000";
            }

            if (scoreInt >= 0 && scoreInt < 100)
            {
                sectionCount = 1;
            }

            if (scoreInt >= 100 && scoreInt < 250)
            {
                sectionCount = 2;
            }

            if (scoreInt >= 250)
            {
                sectionCount = 4;
            }

            if (scoreInt >= 100)
            {
                PlayGamesScript.UnlockAchievement(GPGSIds.achievement_a_warrior);
            }

            if (scoreInt >= 250)
            {
                PlayGamesScript.UnlockAchievement(GPGSIds.achievement_a_lord);
            }

            if (scoreInt >= 500)
            {
                PlayGamesScript.UnlockAchievement(GPGSIds.achievement_the_king);
            }

            controlGame = true;
            coin.GetComponent <Animator> ().Play("CoinDestroy", -1, 0f);
            coinDestroyed = true;
            SpawnCoin();
            controlScore = false;
        }

        if (lifepoints < 1 && zerolife)
        {
            scoreUiscore.text = scoreInt.ToString();
            if (scoreInt > scoreUiscoreInt)
            {
                scoreUiscoreInt       = scoreInt;
                scoreUibestscore.text = "Best Score: " + scoreUiscoreInt.ToString();
                CloudVariables.SetImportantValues(1, scoreUiscoreInt);
                PlayGamesScript.AddScoreToLeaderboard(GPGSIds.leaderboard_leaderboards, CloudVariables.ImportantValues[1]);
                PlayGamesScript.Instance.SaveData();
            }
            controlGame  = true;
            sectionCount = 0;
            menuUi.SetActive(false);
            targetUi.GetComponent <Animator> ().Play("TargetOff", -1, 0f);
            gameUi.SetActive(false);
            scoreUi.SetActive(true);
            coin.GetComponent <Animator> ().Play("CoinDestroy", -1, 0f);
            coinDestroyed = true;
            sections.GetComponent <Animator> ().Play("SectionOff", -1, 0f);
            Camera.GetComponent <Animator> ().Play("CameraMoveToMenu", -1, 0f);
            nTnumber = Numbers [Random.Range(0, Numbers.Length)];
            if (startCounter == nTnumber)
            {
                reward = true;
            }
            else
            {
                reward = false;
            }
            if (reward)
            {
                AdsScript.Instance.GameOver();
            }
            scoreUi.GetComponent <Animator> ().Play("ScoreOn", -1, 0f);
            scoreUiscore.GetComponent <AudioSource>().Play();
            zerolife = false;
        }

        if (thanksoff)
        {
            if (thanksUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).IsName("ThanksOpen") &&
                thanksUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).length <
                thanksUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).normalizedTime)
            {
                thanksUi.SetActive(false);
                thanksoff = false;
            }
        }

        if (gameoff)
        {
            if (gameUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).IsName("GameOff") &&
                gameUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).length <
                gameUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).normalizedTime)
            {
                targetUi.SetActive(false);
                gameUi.SetActive(false);
                menuUi.SetActive(true);
                gameoff = false;
            }
        }

        if (coinSpawned)
        {
            if (coin.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).IsName("CoinSpawn") &&
                coin.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).length <
                coin.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).normalizedTime)
            {
                clickControl = true;
                if (sectionCount == 1)
                {
                    leftbutton.GetComponent <Button> ().interactable  = true;
                    rightbutton.GetComponent <Button> ().interactable = true;
                }
                else
                {
                    leftbutton1.GetComponent <Button> ().interactable  = true;
                    rightbutton1.GetComponent <Button> ().interactable = true;
                    leftbutton2.GetComponent <Button> ().interactable  = true;
                    rightbutton2.GetComponent <Button> ().interactable = true;
                    leftbutton3.GetComponent <Button> ().interactable  = true;
                    rightbutton3.GetComponent <Button> ().interactable = true;
                    leftbutton4.GetComponent <Button> ().interactable  = true;
                    rightbutton4.GetComponent <Button> ().interactable = true;
                }
                coinSpawned = false;
            }
        }


        if (scoreoff)
        {
            if (scoreUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).IsName("ScoreOff") &&
                scoreUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).length <
                scoreUi.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).normalizedTime)
            {
                scoreUi.SetActive(false);
                sectionCount = 0;
                scoreInt     = 0 + rewardPoints;
                score.text   = scoreInt.ToString();
                controlGame  = true;
                sectionCount = 1;
                gameUi.SetActive(true);
                targetUi.SetActive(true);
                gameUi.GetComponent <Animator> ().Play("GameOn", -1, 0f);
                targetUi.GetComponent <Animator> ().Play("TargetOn", -1, 0f);
                sections.GetComponent <Animator> ().Play("SectionOn", -1, 0f);
                SpawnCoin();
                scoreoff = false;
            }
        }
    }