Question by
DroidifyDevs · Jan 30, 2016 at 03:11 PM ·
c#scripting problemtimer-scriptsecondstime.time
How to make hundrenths of seconds in C#?
So I've made this script and it shows seconds and minutes fine:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TimerCounter : MonoBehaviour {
public Text counterText;
public float seconds, minutes, hund;
// Use this for initialization
void Start ()
{
counterText = GetComponent<Text>() as Text;
}
// Update is called once per frame
void Update ()
{
minutes = (int)(Time.time / 60f);
seconds = (int)(Time.time % 60f);
hund = (int)(Time.time % 60f);
counterText.text = minutes.ToString("00") + ":" + seconds.ToString("00") + ":" + hund.ToString("00");
}
}
But I can't figure out how to make hundenths of seconds so the time will show for example: 01(minutes) : 45(seconds) : 16 (hundrenths of seconds).
Any ideas? Thank you!
Comment
Best Answer
Answer by cjdev · Jan 31, 2016 at 12:35 PM
Try hund = (int)((Time.time % 60f - seconds) * 100f);
Thanks, code works flawlessly! Also I had to use Time.timeSinceLevelLoad because it was counting from the time I started the game and would never reset LOL