private IEnumerator moveToNextTile(TileSelect nextTile) { float timePassed = 0; Vector3 currentPos = currentTile.transform.position; currentPos.y = currentTile.getHeight(); Vector3 nextPos = nextTile.transform.position; nextPos.y = currentTile.getHeight(); Vector3 pathToNext = nextPos - currentPos; while (timePassed <= timeToMove) { Vector3 newPos = currentPos + pathToNext * (timePassed / timeToMove); if (timePassed >= timeToMove / 2) { newPos.y = nextTile.getHeight(); } transform.position = newPos; yield return(null); timePassed += Time.deltaTime; } nextPos.y = nextTile.getHeight(); transform.position = nextPos; currentTile.setTileOccupied(false); nextTile.setTileOccupied(true); currentTile = nextTile; }