Graphics Reference
In-Depth Information
4.8 Automatic gameObject self-destructor
4.9 Object spinner
4.10 Scene manager
4.2 The Timer Class
Our timer system will be named TimerClass.cs and the full script looks like this:
public class TimerClass
{
public bool isTimerRunning= false;
private float timeElapsed= 0.0f;
private float currentTime= 0.0f;
private float lastTime= 0.0f;
private float timeScaleFactor= 1.1f; // <-- If you need to scale
// time, change this!
private string timeString;
private string hour;
private string minutes;
private string seconds;
private string mills;
private int aHour;
private int aMinute;
private int aSecond;
private int aMillis;
private int tmp;
private int aTime;
private GameObject callback;
public void UpdateTimer ()
{
// calculate the time elapsed since the last Update()
timeElapsed=Mathf.Abs(Time.realtimeSinceStartup-lastTime);
// if the timer is running, we add the time elapsed to the
// current time (advancing the timer)
if(isTimerRunning)
{
currentTime+=timeElapsed*timeScaleFactor;
}
// store the current time so that we can use it on the next
// update
lastTime=Time.realtimeSinceStartup;
}
Search WWH ::




Custom Search