I have an object that detects (via onTriggerEnter) when units enters an area and it pushes them onto an array. when a unit dies he sends his target numer (which is his position in the array) to the array, so it can null him out, and everything to the right of him shifts down to close the gap, then the array resizes -1 to pop off the last space which is now null. it all woks as intended.
.
But when i start to have massive numbers of enemies battleing at once. every once in a while two things will die close enough to where it seems they get batched into the same update call i guess? so the previously mentioned function, that extracts a badguy, then ends up running twice at the exact same time, causing an error because two functions are trying to manipulate one array, and it just goes all wrong.
.
Is there some way to detect if the function is being called more than once at a single instance? or am i just gonna have to revise my code to work around this?
.
here is the function in question as of right now:
public void ExtractBadGuy(int tNum)
{
if (badGuys.Length == 0)
{
Debug.Log("Extracting a badguy from empty list. wtf.");
return;
}
else if(badGuys.Length > 1)
{
for(int i = tNum; i < badGuys.Length-1; i++)
{
badGuys *= badGuys[i + 1];*
-
}*
-
}*
-
System.Array.Resize<Transform>(ref badGuys, badGuys.Length - 1);*
-
ReAssignBadGuyNumbers();*
- }*