unity3d---倒计时代码
Posted 鬼小妞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity3d---倒计时代码相关的知识,希望对你有一定的参考价值。
using UnityEngine;
using System.Collections;
using System;
public class Timmer : MonoBehaviour {
public GameObject countDown;
public int endTime;
public GUIText UI_Time;
public int currentTime;
public int startTime;
public int second;
public int minute;
private string printTime;
private string stringEndTime;
void Start () {
startTime = 3;
}
void Update () {
endTime = startTime - currentTime;
second = endTime % 60;
minute = endTime / 60;
currentTime = Mathf.CeilToInt(Time.fixedTime); //开始计时
if(second<10)
{printTime = ":0";
}else{printTime = ":";}
stringEndTime = minute + printTime + second;
print ( printTime + second);
print(stringEndTime);
UI_Time.text = stringEndTime; //显示到游戏场景中
//倒计时完毕游戏结束
if(endTime<0)
{
second = 0;
minute = 0;
stringEndTime = minute + printTime + second; //
UI_Time.text = stringEndTime;
GameManager._instance.GameOver(); //跳转到游戏结束场景
}
}
}
以上是关于unity3d---倒计时代码的主要内容,如果未能解决你的问题,请参考以下文章
Unity3D日常开发Unity3D中实现计时器工具类-正计时倒计时暂停计时加速计时