Hi guys,
After about 5 mins of this code running the PC freezes up and I have to reboot. I also have this same code for spawning walls. Am I doing something wrong here?
Thanks.
//-----------------------------------------------------Spawn SandBags-----------------------------------------------//
void SpawnSandbag(){
if(ESandbagAmountSpawned >= ESandbagMax){
canSpawnSandbag = false;
return;
}
if(GameController.cashEnemy < 30){
canSpawnSandbag = false;
return;
}
if(canSpawnSandbag){
print("Start Spawning Sandbag");
if(ESandbagAmountSpawned < ESandbagMax){
if(GameController.cashEnemy > 30){
if(CommandAmountSpawned > 0){
for (int i = 0;i<SandbagSP.Count;i++) {
if(SandbagIndex == ESandbagMax){ // Reset the index based on the List count
SandbagIndex = 0;
}
if(!SandbagSP[i].isTaken) {
SandbagSP[i].isTaken = true;
Transform SpawnPos = SandbagSP[SandbagIndex].transform;
Transform newSB = PoolManager.Pools["Turrets"].Spawn(Sandbag, SpawnPos.transform.position, SpawnPos.transform.rotation);
newSB.GetComponentInChildren<SandbagHealth>().SBSP = SandbagSP[i];
GameController.cashEnemy -= 30;
if(GameController.cashEnemy < 0){
GameController.cashEnemy = 0;
}
SandbagIndex ++;
ESandbagAmountSpawned ++;
print("Spawned a Sandbag");
canSpawnSandbag = false;
break; // break out here so it only spawns 1 sandbag from the index.
}
if(ESandbagAmountSpawned >= ESandbagMax){
canSpawnSandbag = false;
break;
}
if(GameController.cashEnemy < 30){
canSpawnSandbag = false;
break;
}
}
}else{
canSpawnSandbag = false;
SpawnCommand();
return;
}
}else{
canSpawnSandbag = false;
return;
}
}else{
canSpawnSandbag = false;
return;
}
}
}