本文是我翻墙看Backeys的How to make a HIGH SCORE in Unity做出的笔记和教程翻译
最高得分适用于很多类型的小游戏,通过UI记录当前得分和最高得分
先在Hierarchy上创建一个panel三个Text和两个button
三个text分别为“Score”“HighScore”“HighScoreTitle”
两个button分别为“RollDiceButton”“ResetButton”
之后创建脚本
using UnityEngine.UI;
using UnityEngine;
public class RollDice : MonoBehaviour{
public Text Score;
public Text HighScore;
void Start()
{
HighScore.Text = PlayerPrefs.GetInt("HighScore",0).ToString();
}
public void RollDic()
{
int number = Random.Range(1,7);
Score.text = number.ToString();
if(number > PlayerPrefs.GetInt("HighScore",0)
{
PlayerPrefs.SetInt("HighScore",number);
HighScore.text = number.ToString();