Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7190

Unity crashes as the program goes through WaitForSeconds the last time

$
0
0

i have a strange problem. My Code works fine. Everything works as it should until it goes the last time through a foreach loop. The code:

public List<string> waveInput = new List<string>(); //die Eingabe der Welle als Zeichenfolgepublic List<GameObject> enemyTyps = new List<GameObject>();public List<Vector3> path = new List<Vector3>();public GameObject tempPathStart;public int currentWave = 0;public int currentAmountOfEnemies;private int spawnAmountOfEnemies;private double spawnDelay;private List<GameObject> enemyToSpawn = new List<GameObject>();void Start() {    path.Add(tempPathStart.transform.position);    StartCoroutine(function());}IEnumerator function() {    while(waveInput.Capacity >= currentWave) {        if(waveInput[currentWave] == ""&& currentAmountOfEnemies <= 0) {            currentWave++;            enemyToSpawn.Clear();            spawnAmountOfEnemies = 0;        } else if(currentAmountOfEnemies <= 0) {            string _substring = waveInput[currentWave].Substring(0, waveInput[currentWave].IndexOf(";") + 1);            ManageSubstring(_substring);            for(int i = 0; i < spawnAmountOfEnemies; i++) {                foreach(GameObject element in enemyToSpawn) {                    this.SpawnEnemy(element);                    yield return new WaitForSeconds((float)spawnDelay);                }            }        }    }}void ManageSubstring(string _substring) {    string _tempStringAmount = "";    string _tempStringDelay = "";    string _tempStringType = "";    bool _switchAmountDelay = false;    for(int i = 0; i < _substring.Length; i++) {        char c = _substring[i];        if(c >= '0'&& c <= '9') {            if(_switchAmountDelay) {                _tempStringDelay += c;            } else {                _tempStringAmount += c;            }        } else if(c == ';') {        } else if(c == '.') {            _tempStringDelay += c;        } else {            _switchAmountDelay = true;            _tempStringType += c;        }    }    spawnDelay = double.Parse(_tempStringDelay);    spawnAmountOfEnemies = int.Parse(_tempStringAmount);    foreach(char c in _tempStringType) { //die Buchstaben in GameObjekte / Gegner umwandeln        int _tempConvertedInt = TranslateStringToInt(c);        enemyToSpawn.Add(enemyTyps[_tempConvertedInt]);    }}int TranslateStringToInt(char pToConvertChar) {    List<char> _alphabet = new List<char>() {'a','b','c','d','e','f','g','h','i','j','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};    return _alphabet.IndexOf(pToConvertChar);}void SpawnEnemy(GameObject prefab) {    currentAmountOfEnemies++;    GameObject e = Instantiate(prefab) as GameObject;    e.transform.position = path[0];}

the very strange thing as i already said is: the code works, even the line works fine until it goes through the last time. Then Unity crashes and i have no idea what i should do. If some more code is needed for context just say.

Thanks for every answer!


Viewing all articles
Browse latest Browse all 7190

Trending Articles



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