Unity: 2017.3.0f3
Use case : Move an object on click.
I often see Coroutine like the following to move object.
private IEnumerator MoveTo(Vector2 position){
while (/*stop condition*/)
{
float newX = speed * Time.deltaTime;
transform.position = /*with newX*/
yield return null; // <-----------
}
}
I think it should be:
private IEnumerator MoveTo(Vector2 position){
while (/*stop condition*/)
{
yield return null; // <-----------
float newX = speed * Time.deltaTime;
transform.position = /*with newX*/
}
}
I think that in most use case we have to wait the next frame to execute the move action otherwise we take into account the deltaTime that already passed before we managed to move the object.
What do you think ? Am I totally wrong ?
PS: I know that we can use Update() and co. for this kind of use case.