4-6) Updating and Saving The High Score

시그니천·2024년 6월 5일

[ G01 ] ZigZagRacer

목록 보기
20/26

1. BestScoreTex추가

2. Playerprefs로 저장 및 불러오기

  • GameManager
    [SerializeField] private TextMeshProUGUI bestScore_Tex;
    private int bestScore;
    
    private void Start()
    {
        bestScore = PlayerPrefs.GetInt("bestScore");
        bestScore_Tex.text = "Best Score : " + bestScore;
    }
    public void GameOver()
    {
        SaveBestScore();
    }
    private void SaveBestScore()
    {
        if (PlayerPrefs.HasKey("bestScore"))
        {
            // Already have bestscore
            if (score > PlayerPrefs.GetInt("bestScore"))
            {
                PlayerPrefs.SetInt("bestScore", score);
            }
        }
        else
        {
            // Playing for the first time
            PlayerPrefs.SetInt("bestScore", score);
        }
    }

3. GameOver시 점수 업데이트 안되도록

  • GameManager
```cs
    public void GameOver()
    {
                StopCoroutine("UpdateScore");
    }
profile
우주최강개발자

0개의 댓글