Exemplo n.º 1
0
 public void NewOnlineScore(float _score)
 {
     nickname = PlayerPrefs.GetString("localuser");
     if (_score > PlayerPrefs.GetFloat("bestlocalscore"))                 //check if the last score is higher than the best one, if so, update it.
     {
         PlayerPrefs.SetFloat("bestlocalscore", _score);                  // set the local player pref for the score
     }
     uniqueID = SystemInfo.deviceUniqueIdentifier + "_" + nickname + "_"; // creation of the unique identifier for the player
     online.updateOnlineHighscoreData(uniqueID, nickname, _score);        //this will be the information of the player in the database
     online.startPostScores();                                            // will create a new entry in the database with the info given before.
     online.Invoke("startGetScores", 1);                                  //update what the player see in the list, invoke in 1f in case update take more time than estimated
     print("NEW ONLINE SCORE UPDATED");
 }
    void Update()
    {
        if (startNotificationTimer)
        {
            notificationTimer += Time.deltaTime;
        }
        if (notificationTimer >= notificationThreshold)
        {
            notificationBox.text   = "";
            startNotificationTimer = false;
            notificationTimer      = 0f;
        }
        if (Input.GetKeyDown(KeyCode.Return))
        {
            SubmitLeaderboardScore();
        }
        if (startLoading)
        {
            loadTimer += Time.deltaTime;
        }
        if (loadTimer >= loadThreshold)
        {
            HSController.startGetScores();
            startLoading = false;
            loadTimer    = 0f;
        }


        if (setTheScore)
        {
            if (!startLoading)
            {
                if (localPassword == HSController.retrievedID || HSController.retrievedID == "" || HSController.retrievedID == null)
                {
                    HSController.startGetCurrentScore();
                    startLoading = true;
                    startScoring = true;
                }
                else
                {
                    notificationBox.text = "WRONG PASSWORD!";
                    ClearNotificationBox();
                    //  Debug.Log("WRONG PASSWORD!");
                }
                setTheScore = false;
            }
        }

        if (startScoring && !startLoading)
        {
            // Debug.Log("LOCAL SCORE: " + localScore);
            //Debug.Log("RETRIEVED SCORE: " + HSController.retrievedScore);

            if (localScore < HSController.retrievedScore)
            {
                HSController.startPostScores();
                scoresPosted = true;
                startLoading = true;
            }
            else
            {
                notificationBox.text = "your best is higher or equal!";
                ClearNotificationBox();
                //  Debug.Log("SCORE IS LOWER");
            }
            startScoring = false;
        }
        if (scoresPosted && !startLoading && successStarted)
        {
            HSController.startGetScores();

            successText = "SUCCESS!";

            scoresPosted   = false;
            successStarted = false;
            setSuccessText = true;
            rememberMe.shouldUserBeRemembered = true;
        }
        if (setSuccessText)
        {
            //setting the text like this because setting the text after HSController.startGetScores() caused a null reference exception.
            notificationBox.text = successText;
            ClearNotificationBox();
        }
    }