void Toggle_MoveAsteroids() { // SMALL ASTEROID // store all current asteroids in a variable GameObject[] Small_Asteroids = GameObject.FindGameObjectsWithTag("Small_Asteroid"); GameObject[] Medium_Asteroids = GameObject.FindGameObjectsWithTag("Medium_Asteroid"); GameObject[] Big_Asteroids = GameObject.FindGameObjectsWithTag("Big_Asteroid"); // make a variable that can hold all the scripts MoveAsteroid[] Small_AsteroidScripts = new MoveAsteroid[Small_Asteroids.Length]; MoveAsteroid[] Medium_AsteroidScripts = new MoveAsteroid[Medium_Asteroids.Length]; MoveAsteroid[] Big_AsteroidScripts = new MoveAsteroid[Big_Asteroids.Length]; // Small Toggle for (int i = 0; i < Small_Asteroids.Length; i++) { // put each script in the variable that was just made Small_AsteroidScripts[i] = Small_Asteroids[i].GetComponent <MoveAsteroid> (); // then enable or disable the script Small_AsteroidScripts[i].enabled = !Small_AsteroidScripts[i].enabled; } // Medium Toggle for (int i = 0; i < Medium_Asteroids.Length; i++) { // put each script in the variable that was just made Medium_AsteroidScripts[i] = Medium_Asteroids[i].GetComponent <MoveAsteroid> (); // then enable or disable the script Medium_AsteroidScripts[i].enabled = !Medium_AsteroidScripts[i].enabled; } // Big Toggle for (int i = 0; i < Big_Asteroids.Length; i++) { // put each script in the variable that was just made Big_AsteroidScripts[i] = Big_Asteroids[i].GetComponent <MoveAsteroid> (); // then enable or disable the script Big_AsteroidScripts[i].enabled = !Big_AsteroidScripts[i].enabled; } }
private void Awake() { MovementAsteroid = GetComponent <MoveAsteroid>(); AsteroidCirlce = GetComponent <CircleCollider2D>(); }