0

我有以下代码,我想添加 miliSeconds var,以便显示如下内容:

分 : 秒 : miliSeconds

2:35:98

Time.time 是从应用程序开始经过的时间,每帧都会调用更新函数。

var startTime:float;
var timeRemaining:float;

var minutes:int;
var seconds:int;
var miliSeconds:int;
var timeStr:String;

function Start () {
    startTime = 130.0;
}

function Update () {
    timeRemaining = startTime - Time.time;

    minutes = timeRemaining / 60;
    seconds = timeRemaining % 60;
    //miliSeconds = ?
    timeStr = minutes.ToString()+":"+seconds.ToString("D2");

    guiText.text = timeStr;
}
4

1 回答 1

0

如果我正确理解您要执行的操作,请尝试以下代码:

var startTime:float;
var timeRemaining:float;

var minutes:int;
var seconds:int;
var miliSeconds:int;
var timeStr:String;

function Start () {
    startTime = 130.0;
}

function Update () {
    timeRemaining = startTime - Time.time;

    minutes = timeRemaining / 60;
    seconds = timeRemaining;        
    miliSeconds = timeRemaining * 1000;

    seconds -= minutes*60;
    miliSeconds -= seconds*1000;

    timeStr = minutes.ToString()+":"+seconds.ToString("D2")+":"+miliSeconds.ToString();

    guiText.text = timeStr;
}
于 2013-02-05T15:32:08.597 回答