system
October 31, 2011, 6:29pm
1
i have a simple time counter that count just the seconds
var Counter : int = 0;
function Update () {
Counter++;
guiText.text = "Time: "+Counter;
}
but i want a time that count the seconds and minutes im not couding if you helpwith the script will be helpful
@thepra13 This code should work fine.
private float timeRemaining;
void Start()
{
timeRemaining = 61;
}
void Update()
{
timeRemaining -= Time.deltaTime;
if (timeRemaining > 0)
{
float minutes = Mathf.Floor(timeRemaining / 60);
float seconds = Mathf.Floor(timeRemaining % 60);
timerText.text = " " + minutes.ToString("00") + ":" + seconds.ToString("00");
}
}
Subhi
November 1, 2011, 6:20am
3
var Counter = 0.000;
function Update () {
Counter += 1 * Time.deltaTime;
var Counter2 : int;
Counter2 = Counter;
guiText.text = "Time: " + Counter2;
}
RobbynB
September 25, 2012, 5:16pm
4
alright so here is a script I wrote to fix this issue
var min : int;
var sec : int;
var fraction : int;
var timecount : float;
var starttime : float;
var timeCounter : GUIText;
function Start ()
{
starttime = Time.time;
}
function Update () {
timecount = Time.time - starttime;
min = (timecount/60f);
sec = (timecount % 60f);
fraction = ((timecount * 10) %10);
timeCounter.text = String.Format("{00:00}:{1:00}:{2:00}",min,sec,fraction);
}
var counter : int;
var texta : GUIText;
function Update () {
counter1();
}
function counter1 () {
texta.text = "Time: " + counter;
yield WaitForSeconds(1);
counter++;
}
Anxo
October 31, 2011, 6:58pm
2
That answer is on here a lot of times. Just type “timer” in the search. What you are doing in that script is adding 1 on every frame not on every second. so if your computer is computing your script at 60 frames per second, you would have a count of 60 by the time you reach 1 second.
What you are looking for is Time.time, that counts seconds but it is a float not an int, if you search “Timer” here, you will also find how you can display that timer as an int.