Hi I have the following code and I need to add miliSeconds also, please help.
var isPaused:boolean = false;
var startTime:float;
var timeRemaining:float;
function Start () {
startTime = 130.0;
}
function Update () {
timeRemaining = startTime - Time.time;
var minutes:int;
var seconds:int;
var miliSeconds:int;
var timeStr:String;
minutes = timeRemaining / 60;
seconds = timeRemaining % 60;
timeStr = minutes.ToString()+":"+seconds.ToString("D2");
guiText.text = timeStr;
}
#pragma strict
/*
###################################
## ##
##Can not assign a value outside ##
##Of a function a var ##
## ##
###################################
*/
var isPaused:boolean;
var startTime:float;
var timeRemaining:float;
var minutes:int;
var seconds:int;
var miliSeconds:int;
var timeStr:String;
function Start () {
startTime = 130.0;
isPaused = false;
}
function Update () {
if (!isPaused) {
timeRemaining = startTime - Time.time;
minutes = timeRemaining / 60;
seconds = timeRemaining % 60;
if (seconds >= 10) {
timeStr = minutes + ":" + seconds;
}
else if (seconds < 10) {
timeStr = minutes + ":0" + seconds;
}
guiText.text = timeStr;
}
}
Alright, I did some changes around hope you don’t mind. I just did it on myself and it works perfectly or should now. I also added a if statement to display a 0 in front if there is 0-9 seconds left so it has the same looking format and it will look better. Moves your var back if you want to. I just needed to move them so I could see how it ran during gamePlay in my editor.