hi.
i have a script that show the time count down and show on UI canvas text.
but show all decimals, please how can i do to only show seconds please ?
i only need to show only seconds please…
any help will be apreciate so much.

the picture above show 2 seconds and 6… decimals
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class time_count : MonoBehaviour {
public Text time_Text;
public float theTimer_S;
public float theStartTime_S;
void Start ()
{
theTimer_S = theStartTime_S;
}
// Update is called once per frame
void Update ()
{
theTimer_S -= Time.deltaTime;
time_Text.text = "segundos restantes : " + theTimer_S;
}
}
Is that 2.62 seconds? Or is it some other scale of time, so it’s like 2.62 minutes, or 2 minutes 37 seconds?
If it’s already seconds, just format the string when you ‘ToString’ it:
canvas.text = seconds.ToString("0");
Here you can find the numeric format strings that exist.
Standard:
Custom:
1 Like
There’s also Mathf.RoundToInt(insertYourTimeVariableHere);
But that would round, instead of truncating, which wouldn’t be the correct behavior. ToString(“0”) is fine.
–Eric
thanks a lot … now is working
again thanks to all people here…
here is the vide fixed … on the right on screen
is there a way to conver 300 seconds in minuts with seconds please ?
300 seconds = 5 minutes …
thanks for any help
Divide by 60 gives you minutes.
But the seconds will be the decimal values on it. So floor it to get the minutes. And then multiply the fractional part (modulo over 1 to get the fractional part) by 60 to get seconds.
Of course, there is a .Net type that does all this for you easily:
System.TimeSpan
var ts = System.TimeSpan.FromSeconds(amountOfSeconds);
var mins = ts.Minutes;
var secs = ts.Seconds;
Note there are Minutes, and TotalMinutes. Minutes is the integer minutes currently so if you were to write : 3 hours 5 minutes 32 seconds. Where as TotalMinutes (or any of the totals) is the complete and total time. So like TotalSeconds would return 300 in your case.