Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Why does my Simulation keep crashing as soon as this code is called for a second time?

$
0
0
void SpawnCreatures() { int i = 0; while (i <= NumCre) { if (creatureList[i] != null) { Placeholder = DecodeRNA(creatureList[i].GetComponent().GetRNA()); } else { Placeholder = new int[] { 0, 0, 0, 0 }; } //Spawns Creature at Random point between the walls int RandX1 = Random.Range(-41,41); int RandX2 = Random.Range(-27, 27); creatureList[i] = Instantiate(creature, new Vector3(RandX1, RandX2, 0), Quaternion.identity); //Sets the DNA of the new creature to the DNA of the Old creature by using a Placeholder creatureList[i].GetComponent().SetDNA(Placeholder); //Changes DNA creatureList[i].GetComponent().MutateDNA(); i++; } newGenSpawned = true; } // I think it has something to do with the code below int[] DecodeRNA(int newRNA) { int[] DNAtester = new int[4] { 0, 0, 0, 0 }; int RNA = 0; while (RNA != newRNA) { if (DNAtester[0] != 2) { DNAtester[0] = DNAtester[0] + 1; RNA = RNA + 1; } else if (DNAtester[1] != 2) { DNAtester[1] = DNAtester[1] + 1; RNA = RNA + 1; } else if (DNAtester[2] != 2) { DNAtester[2] = DNAtester[2] + 1; RNA = RNA + 1; } else if (DNAtester[3] != 2) { DNAtester[3] = DNAtester[3] + 1; RNA = RNA + 1; } } if (RNA == newRNA) { return DNAtester; } else { return DNAtester; } }

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>