How would I go about creating an ingame timer onscreen while avoid creating garbage? Check the value of a timer, then draw the correct number texture(s) each frame?
Here’s the Time class reference:
This should provide any manner of time-since-XYZ functionality you need to track and craft events around (like displaying a value on a GUIText object, for example).
To measure elapsed time from a starting point, you need to record the starting point and the subtract its value from Time.time whenever you need a time check:-
var startTime: float;
...
function Update() {
if (starting) {
startTime = Time.time;
starting = false;
}
var elapsed = Time.time - startTime;
...
}
You can get the minutes by dividing the elapsed time by 60. The residual seconds are then given by elapsed mod 60:-
var minutes = Mathf.FloorToInt(elapsed / 60);
var seconds = Mathf.FloorToInt(elapsed % 60);
Choosing textures to represent the numbers is generally a matter of storing the textures in an array and choosing the array index that corresponds to the number.
Yeah. I get how to create the timer. I should’ve been more clear. Was wondering if there was any standard way of displaying the numbers.
I have a semi-working solution atm using GUISprite, but it’s not good.
Strings create garbage. If you don’t want that, you can display meshes with UV mapping with a “bitmap font”, and reuse them from a pool so you don’t have to create new meshes each time.