Сожалеем, но текст оригинала доступен только зарегистрированным пользователям. |
|
|
|
|
|
|
|
|
public void UpdateTimer () { // calculate the time elapsed since the last Update() timeElapsed=Mathf.Abs(Time.realtimeSinceStartup-lastTime);
ilia1395
26.10.14 в 13:10
|
|
|
|
|
// 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; }
ilia1395
26.10.14 в 13:11
|
|
|
|
|
|
|
|
|
|
|
public void StartTimer () { // set up initial variables to start the timer isTimerRunning=true; lastTime=Time.realtimeSinceStartup; }
ilia1395
26.10.14 в 13:11
|
|
|
|
|
public void StopTimer () { // stop the timer isTimerRunning=false; }
ilia1395
26.10.14 в 13:11
|
|
|
|
|
public void ResetTimer () { // resetTimer will set the timer back to zero timeElapsed=0.0f; currentTime=0.0f; lastTime=Time.realtimeSinceStartup; }
ilia1395
26.10.14 в 13:11
|
|
|
|
|
|
|
|
public string GetFormattedTime () { // carry out an update to the timer so it is 'up to date' UpdateTimer();
ilia1395
26.10.14 в 13:11
|
|
|
|
|
|
|
|
// grab minutes aMinute=(int)currentTime/60; aMinute=aMinute%60; // grab seconds aSecond=(int)currentTime%60; // grab milliseconds aMillis=(int)(currentTime*100)%100;
ilia1395
26.10.14 в 13:11
|
|
|
|
|
// format strings for individual mm/ss/mills tmp=(int)aSecond; seconds=tmp.ToString(); if(seconds.Length<2) seconds="0"+seconds; tmp=(int)aMinute; minutes=tmp.ToString(); if(minutes.Length<2) minutes="0"+minutes; tmp=(int)aHour; hour=tmp.ToString(); if(hour.Length<2) hour="0"+hour; tmp=(int)aMillis; mills=tmp.ToString(); if(mills.Length<2) mills="0"+mills;
ilia1395
26.10.14 в 13:11
|
|
|
|
|
|
|
|
// pull together a formatted string to return timeString=minutes+":"+seconds+":"+mills; return timeString; }
ilia1395
26.10.14 в 13:11
|
|
|
|
|
public int GetTime () { // remember to call UpdateTimer() before trying to use this // function, otherwise the time value will not be up to date return (int)(currentTime); }
ilia1395
26.10.14 в 13:12
|
|
|
|
|