首页 > 代码库 > unity3d---倒计时代码

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---倒计时代码