- Home /
Checking for input by using Update or a Coroutine - is there a timing difference?
I was just looking at a project's code and saw that it uses a coroutine for checking for input. Is there a functional difference between the following?
private IEnumerator WaitForTap()
{
while (true)
{
if (Input.GetMouseButtonDown(0))
{
//do something
}
yield return 0;
}
}
or
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//do something
}
}
Say that I would want to record the timestamp of the tap in //do something - would there be a difference in precision between the two?
Answer by Kishotta · Jun 27, 2017 at 08:29 PM
I'm not sure if Input updates mid frame (I suspect it does not). If it does though, assuming your game is running at 60fps, you're talking about a difference of 16 thousandths of a second. The top version is simpler and less error prone. I'd go with it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Read and interpret data from .txt in real time, line by line 0 Answers
Accurate millisecond timed thread 2 Answers
Timed actions 1 Answer
How do I convert the game to start time? 0 Answers
how well does unity work for turn-based game time-type? 3 Answers