设置成绩
逻辑部分
当每消除一行,成绩加5分。
代码部分
public Text Score;//用于绑定成绩的文本组件,好对文本的内容进行修改
public static int score = 0;
void Start()
{
//对大小写敏感
timer = GameObject.Find("Canvas/Timer").GetComponent<Text>();
Score = GameObject.Find("Canvas/Score").GetComponent<Text>();
//得到游戏开始时间(单位:s)
startTime = Time.time;
}
// Update is called once per frame
void Update()
{
//游戏运行了多长时间(单位:s)
time=Time.time - startTime;
//秒数
int seconds=(int)time % 60;
//分数
int minutes = (int)time / 60;
//其中:前面的0 1指的是第几个参数 :后面00表示由几位组成 {}之间的:是要显示出来的
string strTime = string.Format("{0:00}:{1:00}",minutes,seconds);
timer.text = strTime;
Score.text = score.ToString();
}
更多俄罗斯方块精彩文章请点击专题:俄罗斯方块游戏集合 进行学习。
更多有趣的经典小游戏实现专题,分享给大家:
C++经典小游戏汇总
python经典小游戏汇总
python俄罗斯方块游戏集合
JavaScript经典游戏 玩不停
javascript经典小游戏汇总
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易采站长站。










