private void Start() { platformsVertOffset = platformsStartVertOffset; if (!ObjectsPool.IsEmpty) { lastSpawned = ObjectsPool.GetItem().transform; startPos = lastSpawned.position; while (!ObjectsPool.IsEmpty) { SpawnPlatform(); } } }
private IEnumerator OnGameRetryCoroutine() { yield return(null); if (!ObjectsPool.IsEmpty) { lastSpawned = ObjectsPool.GetItem().transform; lastSpawned.position = startPos; Vector3 scale = lastSpawned.localScale; scale.x = maxPlatformLength; lastSpawned.localScale = scale; platformsVertOffset = platformsStartVertOffset; } }
private void SpawnPlatform() { Transform current = ObjectsPool.GetItem().transform; Vector3 scale = current.localScale; scale.x = Random.Range(minPlatformLength, maxPlatformLength); current.localScale = scale; float offsetX = lastSpawned.localScale.x * 0.45f; current.position = new Vector3(lastSpawned.position.x + offsetX + current.localScale.x / 2, lastSpawned.position.y + platformsVertOffset, lastSpawned.position.z); platformsVertOffset = -platformsVertOffset; lastSpawned = current; }