- Home /
more resource efficient TIMER
which of these two timers is more resource efficient?
Timer 1:
float timeCount = 10;
void Update()
{
timeCount -= Time.deltaTime;
guiText.text = timeCount.ToString("F0");
if (timeCount > 0)
{
guiText.text = timeCount.ToString("F0");
}
else
{
Debug.Log("Time is up.");
guiText.text = "Time's up.";
}
}
Timer 2:
int timeCount = 10;
void Start()
{
InvokeRepeating("Timer",1,1);
}
void Timer()
{
timeCount--;
guiText.text = timeCount.ToString();
if(timeCount < 1)
{
CancelInvoke("Timer");
Debug.Log("Time is up.");
guiText.text = "Time's up.";
}
}
Answer by Kiwasi · Jun 09, 2014 at 10:11 AM
Timer 2
Reasoning: The resolution on timer 2 is much more coarse, it only updates the guiText once per second, as opposed to every frame.
Answer by snarf · Jun 09, 2014 at 10:17 AM
I would choose option two mainly for the reason that it makes your code look cleaner. Performance-wise you wouldn't notice any difference. Also performance optimisation requires that you do benchmarks and you shouldn't waste any time on it early in development.
Hope you find my answer just as good as I had planned it to beeee (I'm awsum)
Your answer
Follow this Question
Related Questions
SpeedBoost won't reset : Problem with either WaitForSeconds or Coroutine (Solved) 2 Answers
Problem with speed boost 2 Answers
Having a speed counter 2 Answers
Speed Affect Timer 1 Answer
Timer Progress Bar 2 Answers