// Use this for initialization void Start() { //First we get all the asteroids in children, then we use static class AsteroidCounter to hold the number of asteroids asteroids = GetComponentsInChildren <AsteroidScript> (); AsteroidCounter.setCounter(asteroids.Length); StartCoroutine("AttackPlayer"); }
//overwrites the parent class (AsteroidScript) explode method b/c we don't want to spawn more asteroids on death public override void Explode() { Instantiate(explosion, transform.position, Quaternion.identity); if (Random.Range(0, 100) <= spawn1upChance) { Instantiate(OneUp, transform.position, Quaternion.identity); } AsteroidCounter.decrememt(1); Destroy(gameObject); }
//Instantiantes the Explosion prefab at the asteroids current position //and decrements the amount of asteroids by 1, then destroys the GameObject public virtual void Explode() { Instantiate(SmallAsteroid, transform.position + (Random.onUnitSphere * -2), Quaternion.identity, transform.parent); Instantiate(SmallAsteroid, transform.position + (Random.onUnitSphere * 2), Quaternion.identity, transform.parent); Instantiate(explosion, transform.position, Quaternion.identity); //rb.AddExplosionForce (1000, transform.position, 100); if (Random.Range(0, 100) <= spawn1upChance) { Instantiate(OneUp, transform.position, Quaternion.identity); } //AsteroidCounter.increment (2); AsteroidCounter.decrememt(1); Destroy(gameObject); }
//after a specified delay, choose a random asteroid and send it towards the player IEnumerator AttackPlayer() { //makes sure that all the asteroids haven't been destoryed if (AsteroidCounter.counter == 0) { yield break; } yield return(new WaitForSeconds(time)); //Since the player can destroy asteroids at any time, //we get the asteroids in children again to prevent using an asteroid that's been destroyed asteroidsArray = GetComponentsInChildren <AsteroidScript> (); AsteroidCounter.setCounter(asteroidsArray.Length); int num = Random.Range(0, asteroidsArray.Length); if (asteroidsArray.Length > 0 && asteroidsArray [num] != null) { asteroidsArray [num].Attack(); } //Debug.Log ("Asteroid number " + num + " is attacking!!"); StartCoroutine("AttackPlayer"); }
public void IncrementAsteroid() { AsteroidCounter.increment(1); }
void Start() { Singleton = this; textCount = GetComponent<Text>(); }