Increasing through a list after an object has been destroyed

Recently, I’ve been working on an educational FPS game - once you ‘tag’ an enemy (Destroy(GameObject) etc on a prefab that’s spawned on level load), the idea is that a variable will increase through a list of preset sums which is going to be displayed.

The one problem I’ve come across, is having the list count be increased after the correct enemy (each is named with their answer, e.g. EnemyNumber1, EnemyNumber2 etc). This is the last thing I have yet to code and I’m come across a blank.

Basically, I want to increase through a list after a certain prefab has been destroyed. This would then be put into another variable to track it and used to output to a text line. Does anyone have any advice for this specific thing?

Thanks.

From your very blurry description I think what you want is to store a count of destroyed enemies grouped by their names. A’la: I have destroyed 3 Joes and 5 Bens.

Here is what you can do:

public class DestroyedEnemyEntry
{
   public string name;
   public int count;
}

// Later

private Dictionary<string, DestroyedEnemyEntry> _destroyedEnemyEntriesByName = ...;

// Later

_destroyedEnemyEntriesByName["Joe"] = new DestroyedEnemyEntry("Joe", 0);
_destroyedEnemyEntriesByName["Ben"] = new DestroyedEnemyEntry("Ben", 0);

// Later

string destroyedEnemyName = /* However you communicate named enemy destruction */;
_destroyedEnemyEntriesByName[destrioyedEnemyName].count ++;
Debug.Log(string.Format("There have been {0} of {1}s destroyed", _destroyedEnemyEntriesByName[destrioyedEnemyName].count.ToString(), destrioyedEnemyName));

Check if the gameObject is true, if it is true then you can perform work on it, if it is false, then move on and not do any work on it.

public var arr : GameObject;

for(var scan=0;scan < arr.length;scan++)
{
if(arr[scan])
{… work on it}

}