IEnumerator SuccessSequence() { //Display success message StingerSFXController.Instance.PlayStingerHit(66, 3); yield return(new WaitForSeconds(3)); //dismiss and destroy all asteroids float waitTime = 0; foreach (GameObject asteroid in asteroids) { LerpAsteroidScale scaleLerp = asteroid.GetComponent <LerpAsteroidScale>(); if (scaleLerp != null) { waitTime = scaleLerp.duration; scaleLerp.BeginLerp(-1); } } yield return(new WaitForSeconds(waitTime)); currentLevel++; asteroids.Clear(); Destroy(currentCharacter); Destroy(currentDestinationObject); Destroy(currentStartObject); StartLevel(currentLevel); yield return(null); }
public void CreateAsteroids() { _numAsteroidsToCreate = (int)(experienceManager.currentNumberOfBounces * difficultyMultiplier); for (int i = 0; i < _numAsteroidsToCreate; i++) { GameObject newAsteroid = Instantiate(asteroidPrefabs[Random.Range(0, asteroidPrefabs.Count - 1)]) as GameObject; LerpAsteroidScale scaleLerp = newAsteroid.GetComponentInChildren <LerpAsteroidScale>(); scaleLerp.BeginLerp(1); experienceManager.asteroids.Add(newAsteroid); Vector3 vecTowardHome = experienceManager.currentDestinationObject.transform.position - Camera.main.transform.position; Vector3 midPointPosition = Camera.main.transform.position + vecTowardHome.normalized * vecTowardHome.magnitude / 2; newAsteroid.transform.position = midPointPosition + new Vector3( Random.Range(-asteroidRangeCircumference, asteroidRangeCircumference), Random.Range(0, asteroidRangeCircumference), Random.Range(-asteroidRangeCircumference, asteroidRangeCircumference) ); float randScale = Random.Range(0.5f * newAsteroid.transform.localScale.x, 1.1f * newAsteroid.transform.localScale.x); newAsteroid.transform.localScale = new Vector3(randScale, randScale, randScale); newAsteroid.transform.rotation = Random.rotation; } }