Example #1
0
    public void CalculateScore()
    {
        if (Score > LastScore)
        {
            PlayerPrefs.SetInt("Score", Score);
        }

        EndUI.SetActive(true);
        //只有物体显示后才能获取到对象,否则为抛出空指针异常
        NowScore  = GameObject.Find("NowScore");
        HighScore = GameObject.Find("HighScore");
        NowScore.GetComponent <Text>().text  = Score.ToString();
        HighScore.GetComponent <Text>().text = LastScore.ToString();
        if (Input.GetKey(KeyCode.Mouse0))
        {
            SceneManager.LoadScene("UI");
        }
    }
Example #2
0
 public void CalculateScore()
 {
     if (Score > LastScore)
     {
         PlayerPrefs.SetInt("Score", Score);
     }
     if (EndUI == null)
     {
         return;
     }
     EndUI.SetActive(true);
     NowScore  = GameObject.Find("NowScore");
     HighScore = GameObject.Find("HighScore");
     NowScore.GetComponent <Text>().text  = Score.ToString();
     HighScore.GetComponent <Text>().text = LastScore.ToString();
     GameObject.Find("Text").GetComponent <Text>().text = string.Format("Score\r\n{0}\n\nHigh score\n{1}", Score.ToString(), LastScore.ToString());
     if (Input.GetKey(KeyCode.Mouse0))
     {
         SceneManager.LoadScene("UI");
     }
 }