private IEnumerator Move(GameObject gameObject, int prevPlatformCount, LevelConfig level) { if (gameObject == null) { yield return(new WaitForEndOfFrame()); } else { var expectedYPosition = gameObject.transform.position.y - 2 * Camera.main.orthographicSize + 0.01f; while (gameObject.transform.position.y >= expectedYPosition) { gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, gameObject.transform.position - new Vector3(0, 2 * Camera.main.orthographicSize, 0), movementSpeedOfPlatforms / 2); yield return(new WaitForEndOfFrame()); if (gameObject == null) { break; } } } if (prevPlatformCount != 0) { DestroyPrevPlatforms(prevPlatformCount); prevPlatformsDestroyed = true; } foreach (GameObject platform in platforms) { if (platform.GetComponent <MovingObstacle>()) { platform.GetComponent <MovingObstacle>().StartMoving(); } } if (FindObjectOfType <Target>() == null) { Instantiate(targetPrefab, level.GetTargetPosition(), Quaternion.identity); } }