private void TryGeneratePlatforms() { var playerPosition = player.transform.position; var up = playerPosition.y + Camera.main.orthographicSize + _halfPlatformHeight; PlatformBase platformBase = GetRandomPlatformType(); while (up > _activePlatforms[_activePlatforms.Count() - 1].transform.position.y) { var spawnPosition = new Vector3(); spawnPosition.x = Random.Range(_levelWidth, -_levelWidth); spawnPosition.y = _activePlatforms[_activePlatforms.Count() - 1].transform.position.y + Random.Range(minY, maxY); var platform = Instantiate(platformBase, spawnPosition, Quaternion.identity); _activePlatforms.Add(platform); if (enemiesManager.CanCreateEnemy((int)player.MaxHeight)) { platform.InstantiateEnemy(enemy, enemiesManager); } } }