Avançar para o conteúdo principal

Mensagens

A mostrar mensagens de setembro, 2018

Unity3D Coroutines

Coroutines are functions that maintain status while returning code execution to the method that called them. They are useful for the development of games to allow the execution of certain code over several frames. For example to animate the camera of the game we could execute the following code: for(int i=0;i<100;i++){     transform.position += new Vector3(1, 0,0); } If this code is within a function that is executed normally it is not possible to see the camera moving along the X axis since the game scenario update only occurs at the end of the cycle and not during the execution of this. In order to see the movement of the camera, it is necessary to perform an iteration of the cycle and then update the scene (rendering) and then continue the cycle with one more iteration and refresh the scene again, in this case what's needed is to interrupt the execution and to resume without losing the state, for this we can implement a coroutine. A coroutine is just an IEnumera