private void GeneratePlatforms() { GameObject firstPlatform = _factory.GetPlatform(PlatformType.Simple); Vector3 firstPosition = new Vector3(_lvlWidth / 2, _platformSize.y); firstPlatform.transform.position = firstPosition; _platforms.Add(firstPlatform); float startPos = _platforms[0].transform.position.y + _platformSize.y * 1.5f; foreach (PlatformInterval platformInterval in _data.PlatformIntervals) { Dictionary <PlatformType, float> ratios = ComputeRatios(platformInterval.PlatformsRatio); for (float currentHeight = platformInterval.IntervalStart + startPos; currentHeight < platformInterval.IntervalEnd; currentHeight += (Random.Range(platformInterval.MinDist, platformInterval.MaxDist) + _platformSize.y)) { PlatformType type = GetPlatformType(ratios); GameObject platform = _factory.GetPlatform(type); if (type == PlatformType.Moving) { platform.GetComponent <MovingPlatform>().SetSpeed(platformInterval.MovingPlatformSpeed); } Vector3 position = new Vector3(Random.Range(_platformSize.x / 2, _lvlWidth - _platformSize.x / 2), currentHeight); platform.transform.position = position; _platforms.Add(platform); _allObjects.Add(platform); } } }