Question by
Ocean257 · May 11, 2016 at 02:13 PM ·
c#coroutinesstartcoroutine
how did the game developer of 2048 made their tiles to move smoothly ? see the detail question below
I have made the complete copy of 2048 game but i have moved by tiles by teleporting (no smoothness moving of tiles like it was in original game)
I have used the following code for smothness of moving tiles.
//GameManager script
void MoveRight () {
//some code ..
AnimateTileMovement (newPosition); // newposition is the position to whihc the tiles is going to move
//some code which i need to execute (ONLY AFTER MY COMPLETE MOVEMENT OF TILE)
// BUT AS SOON AS TileMovement return its first null this code execture which is creating a lot of problem , what should i do ?
//to stop execution these code until the tiles have moved towards its desired newPosition
}
//TilesMovement Script
public void AnimationTileMovement(Vector3 newPosition) {
StartCoroutine ("TileMovement", newPosition);
}
IEnumerator TileMovement(Vector3 newPosition) {
while (transform.position != newPosition) {
transform.position = Vector3.MoveTowards (transform.position, newPosition, speedTile * Time.deltaTime);
yield return null;
}
}
i have been spending days to achieve this but i am not able to do how to stop executing the code below StartCoroutine ("TileMovement", newPosition)
as the code gets executed at the very first movement when the IEnumerator TileMovement(Vector3 newPosition)
yeild it first null ?
I have read this Article and tried also but unable to do so please suggest me what to do
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612080601im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
IEnumerator inner functions 0 Answers
Coroutine not executing second time 0 Answers
Determine Audio Clip Length From An Array And Then Add A Delay 1 Answer