- Home /
Inspector not showing my public changes.
im making a mass spawn script and i am trying to set the waves of objects to spawn. In the inspector it only shows Wave1, but not 2, 3, or 4.
I attached the script Can anyone help?
using UnityEngine; using System.Collections; [System.Serializable] //created the following as a class so takes up less space in inspector //Lists the creep then how many creeps in the wave for designer adjust public class CreaturesWave1 { public GameObject enemy1; public int numEnemy1InWave1 = 5; public GameObject enemy2; public int numEnemy2InWave1 = 0; public GameObject enemy3; public int numEnemy3InWave1 = 0; public GameObject enemy4; public int numEnemy4InWave1 = 0; } public class CreaturesWave2 { public GameObject enemy1; public int numEnemy1InWave1 = 5; public GameObject enemy2; public int numEnemy2InWave1 = 0; public GameObject enemy3; public int numEnemy3InWave1 = 0; public GameObject enemy4; public int numEnemy4InWave1 = 0; } public class CreaturesWave3 { public GameObject enemy1; public int numEnemy1InWave1 = 5; public GameObject enemy2; public int numEnemy2InWave1 = 0; public GameObject enemy3; public int numEnemy3InWave1 = 0; public GameObject enemy4; public int numEnemy4InWave1 = 0; } public class CreaturesWave4 { public GameObject enemy1; public int numEnemy1InWave1 = 5; public GameObject enemy2; public int numEnemy2InWave1 = 0; public GameObject enemy3; public int numEnemy3InWave1 = 0; public GameObject enemy4; public int numEnemy4InWave1 = 0; } public class Spawner : MonoBehaviour { public GameObject[] WayPointsLevel1 = new GameObject[5]; //sets the array that holds the waypoints for wave 1 in order as dropped into the inspector public GameObject spawnLoc; //sets up a spawn location where we can use all the creeps when we first start the level public GameObject startPoint; //sets up a staging area that the creep 'pops' to before starting its path //The following creates arrays for each creature public string enemy1Name; public string enemy2Name; public string enemy3Name; public string enemy4Name; private GameObject[] enemy1; private GameObject[] enemy2; private GameObject[] enemy3; private GameObject[] enemy4; //variables created to be used as a counter private int numEnemy1; private int numEnemy2; private int numEnemy3; private int numEnemy4; public float spawnRate = 0.7f; //Instantiates the class so our Spawner class can use it public CreaturesWave1 Wave1; public bool Wave1Enabled; public CreaturesWave2 Wave2; public bool Wave2Enabled; public CreaturesWave3 Wave3; public bool Wave3Enabled; public CreaturesWave4 Wave4; public bool Wave4Enabled; void Start () { Wave1Enabled = true; Wave2Enabled = false; Wave3Enabled = false; Wave4Enabled = false; } // Use this for initialization void Update() { if (Wave1Enabled == true) { //I cache the number so I can iterate without using a property //which would have to be looked up each iteration during CreateCreeps() numEnemy1 = Wave1.numEnemy1InWave1; numEnemy2 = Wave1.numEnemy2InWave1; numEnemy3 = Wave1.numEnemy3InWave1; numEnemy4 = Wave1.numEnemy4InWave1; //There I create "holding" arrays for each creep we are going to make //this way we can activate/deactivate them easily enemy1 = new GameObject[numEnemy1]; enemy2 = new GameObject[numEnemy2]; enemy3 = new GameObject[numEnemy3]; enemy4 = new GameObject[numEnemy4]; //Starts instantiating the creeps, stores them, then deactivates them CreateCreeps(numEnemy1, numEnemy2, numEnemy3, numEnemy4); //Moves creeps to starting area and activates them StartCoroutine(LaunchCreeps(spawnRate, numEnemy1, numEnemy2, numEnemy3, numEnemy4)); } else if (Wave2Enabled == true) { //I cache the number so I can iterate without using a property //which would have to be looked up each iteration during CreateCreeps() numEnemy1 = Wave2.numEnemy1InWave1; numEnemy2 = Wave2.numEnemy2InWave1; numEnemy3 = Wave2.numEnemy3InWave1; numEnemy4 = Wave2.numEnemy4InWave1; //There I create "holding" arrays for each creep we are going to make //this way we can activate/deactivate them easily enemy1 = new GameObject[numEnemy1]; enemy2 = new GameObject[numEnemy2]; enemy3 = new GameObject[numEnemy3]; enemy4 = new GameObject[numEnemy4]; //Starts instantiating the creeps, stores them, then deactivates them CreateCreeps(numEnemy1, numEnemy2, numEnemy3, numEnemy4); //Moves creeps to starting area and activates them StartCoroutine(LaunchCreeps(spawnRate, numEnemy1, numEnemy2, numEnemy3, numEnemy4)); } else if (Wave3Enabled == true) { //I cache the number so I can iterate without using a property //which would have to be looked up each iteration during CreateCreeps() numEnemy1 = Wave3.numEnemy1InWave1; numEnemy2 = Wave3.numEnemy2InWave1; numEnemy3 = Wave3.numEnemy3InWave1; numEnemy4 = Wave3.numEnemy4InWave1; //There I create "holding" arrays for each creep we are going to make //this way we can activate/deactivate them easily enemy1 = new GameObject[numEnemy1]; enemy2 = new GameObject[numEnemy2]; enemy3 = new GameObject[numEnemy3]; enemy4 = new GameObject[numEnemy4]; //Starts instantiating the creeps, stores them, then deactivates them CreateCreeps(numEnemy1, numEnemy2, numEnemy3, numEnemy4); //Moves creeps to starting area and activates them StartCoroutine(LaunchCreeps(spawnRate, numEnemy1, numEnemy2, numEnemy3, numEnemy4)); } else if (Wave4Enabled == true) { //I cache the number so I can iterate without using a property //which would have to be looked up each iteration during CreateCreeps() numEnemy1 = Wave4.numEnemy1InWave1; numEnemy2 = Wave4.numEnemy2InWave1; numEnemy3 = Wave4.numEnemy3InWave1; numEnemy4 = Wave4.numEnemy4InWave1; //There I create "holding" arrays for each creep we are going to make //this way we can activate/deactivate them easily enemy1 = new GameObject[numEnemy1]; enemy2 = new GameObject[numEnemy2]; enemy3 = new GameObject[numEnemy3]; enemy4 = new GameObject[numEnemy4]; //Starts instantiating the creeps, stores them, then deactivates them CreateCreeps(numEnemy1, numEnemy2, numEnemy3, numEnemy4); //Moves creeps to starting area and activates them StartCoroutine(LaunchCreeps(spawnRate, numEnemy1, numEnemy2, numEnemy3, numEnemy4)); } } void CreateCreeps(int Mon1, int Mon2, int Mon3, int Mon4) { //a series of for statements (one per creep type) to spawn the creeps all at once //when the wave loads for(int i = 0; i < Mon1; i++) { GameObject enemy1Creep = Instantiate(Wave1.enemy1, spawnLoc.transform.position, spawnLoc.transform.rotation) as GameObject; enemy1Creep.name = enemy1Name; enemy1[i] = enemy1Creep; enemy1[i].SetActive(false); } for(int i = 0; i < Mon2; i++) { GameObject enemy2Creep = Instantiate(Wave1.enemy2, spawnLoc.transform.position, spawnLoc.transform.rotation) as GameObject; //creates it enemy2Creep.name = enemy2Name; //names it enemy2[i] = enemy2Creep; //stores it in array enemy2[i].SetActive(false); } for(int i = 0; i < Mon3; i++) { GameObject enemy3Creep = Instantiate(Wave1.enemy3, spawnLoc.transform.position, spawnLoc.transform.rotation) as GameObject; enemy3Creep.name = enemy3Name; enemy3[i] = enemy3Creep; enemy3[i].SetActive(false); } for(int i = 0; i < Mon4; i++) { GameObject enemy4Creep = Instantiate(Wave1.enemy4, spawnLoc.transform.position, spawnLoc.transform.rotation) as GameObject; enemy4Creep.name = enemy4Name; enemy4[i] = enemy4Creep; enemy4[i].SetActive(false); } } IEnumerator LaunchCreeps(float spawnRate, int Mon1, int Mon2, int Mon3, int Mon4) { for(int i = 0; i < Mon1; i++) { enemy1[i].SetActive(true); enemy1[i].transform.position = startPoint.transform.position; yield return new WaitForSeconds(spawnRate); } for(int i = 0; i < Mon2; i++) { enemy2[i].SetActive(true); enemy2[i].transform.position = startPoint.transform.position; yield return new WaitForSeconds(spawnRate); } for(int i = 0; i < Mon3; i++) { enemy3[i].SetActive(true); enemy3[i].transform.position = startPoint.transform.position; yield return new WaitForSeconds(spawnRate); } for(int i = 0; i < Mon4; i++) { enemy4[i].SetActive(true); enemy4[i].transform.position = startPoint.transform.position; yield return new WaitForSeconds(spawnRate); } } }
Hi sir, you should reformat your code, also i suggest you to not put the whole code since it's a mess, post only the variables maybe.
Answer by Kirbyrawr · Aug 24, 2014 at 02:49 AM
You should put [System.Serializable] on the top of ALL the classes like this:
[System.Serializable]
public class CreaturesWave1
[System.Serializable]
public class CreaturesWave2
[System.Serializable]
public class CreaturesWave3
[System.Serializable]
public class CreaturesWave4