Instantiated enemies not adding to kill count

Hello, I’ve seen a few posts about this, but nothing seems to be working

I have an “enemy” preFab and a “bullet” preFab, the bullets fire out when you click fire1, and the enemies die (Destroy) when the bullets collide with them. The enemies are being created with IEnumerator + StartCoroutine

I’m trying to retrieve when the enemy is destroyed - 6 enemies spawn at once

void OnCollisionEnter (Collision other)
{
	rigidbody.useGravity = true;
	rigidbody.AddForce(0,-100,0);

	if(other.gameObject.tag == "enemy")
	{
		newKill = true;
		Debug.Log("HIT");
		killCount = 1;
	}
}

That returns 6 “HIT”'s when the 6 enemies die, however the bool “newKill” doesn’t change from false to true in the inspector - I initialize it like so:

public bool newKill = false;

which I think is the problem, I can’t get this data to cross classes, which would allow me increment a killCounter in another class - “GameData”

if(newKill)
{
	killCounter += 1;
	newKill = false;
}

I think the problem is because the objects are instantiated and destroy to quickly??

Any thoughts?

In your killCounter class just create a public function that can be called by your enemies in their OnCollisionEnter function.

Something like:

public void incrementKillCounter() {
    killCounter += 1;
}

And in your enemy class simply call that function. You will need to save an instance of GameData for your enemy to call it though or make everything static.