I would like to use my current if loop to generate names, if I have “p = 1 to 9” I would like to use the p from my current loop to generate a variable name for example planet1, planet2 etc. (planet + p = planet1)
string[] planet1;
string[] planet2;
string[] planet3;
string[] planet4;
string[] planet5;
string[] planet6;
string[] planet7;
string[] planet8;
string[] planet9;
if (sFolder) { // Checks to see if there is a Satellites folder
var numSat = sFolder.transform.childCount;
satellites[0] = "" + numSat; // Adds Satellite amount at the given index
if (numSat != 0) for (int s = 1; s <=9; s++){
var sNameNo = GameObject.Find("Galaxy" + cSystem + "/Planets/" + p + "/Satellites/" + s);
if (sNameNo) {
satelliteName = GameObject.Find("Galaxy" + cSystem + "/Planets/" + p + "/Satellites/" + s).GetComponent<Info>().Name;
satellites ~~= satelliteName; // Adds Satellite at the given index~~
~~ var script = sNameNo.GetComponent();~~
~~ if (script == null) sNameNo.AddComponent(“sOrbitAndRotate”);}}~~
// for (int i = 0; i < satellites.Length; i++){ print (planetName + " satellites[" + i + "] = " + satellites*);}*
* if (p == 1) planet1 = satellites;*
* if (p == 2) planet2 = satellites;*
* if (p == 3) planet3 = satellites;*
* if (p == 4) planet4 = satellites;*
* if (p == 5) planet5 = satellites;*
* if (p == 6) planet6 = satellites;*
* if (p == 7) planet7 = satellites;*
* if (p == 8) planet8 = satellites;*
* if (p == 9) planet9 = satellites;*
* satellites = new string[10];*
As you can see its pretty much the same code, I like to save satellites to their planets before its reset. This code works fine, but its large. Imagine if I have more then 9 planets.
Id be nice if it looked something like this.
[planet+p] = satellites;} // or however you do this.
satellites = new string[10];