Increment in every millisecond realtime?
Hi, im try to make tycoon game, i know how to increment for every second but how about +1 in every millisecond in real time?
Comment
Best Answer
Answer by Arkaid · Aug 10, 2016 at 03:21 AM
I don't know what do you mean by "real time", since your updates depend on your framerate, and I really really doubt that happens every millisecond.
That said, you can easily get the amount of miliseconds elapsed between frames using Time.deltatime.
public class MillisecondCounter : MonoBehaviour
{
float elapsed;
int milliseconds { get { return Mathf.FloorToInt(elapsed * 1000); } }
void Start()
{
elapsed = 0;
}
void Update()
{
elapsed += Time.deltaTime;
}
}
You can use that milliseconds value to increment whatever you need.
I agree here. Time.deltaTime is what your looking for inside your Update() function.