foreach loop in OnCollisionStay

greetings
i’m trying to make hp for a wall, but i want to have each enemy hitting the wall doing damage separately (and having a separate attackcooldown timer for each one), does anyone know how i can make one?

i have this:

	private int HP;
	private List<Transform> enemies = new List<Transform>();

	void OnCollisionEnter(Collision hit){
		enemies.Add (hit.gameObject);
	}

	void OnCollisionStay(Collision collide){
		if (collide.gameObject.tag == "Enemy2") {
			HP -= 10;
		} else if (collide.gameObject.tag == "Enemy1") {
			HP -= 5;
		}
		if (HP <= 0) {
			Destroy(this.gameObject);
		}
	}

I didn’t get what you meant by having a separate timer, but what you can probably do is add a script to your enemies (if you don’t already have one). Then add a public int wallDamage to it and subtract it from your wall’s HP on collision!

void OnCollisionStay(Collision collide){
  Enemy enemy = collide.gameObject.GetComponent<Enemy>(); //Enemy is the script in which you added the wallDamage int
  if(enemy != null)
    HP -= enemy.wallDamage;
  if(HP <= 0)
    Destroy(this.gameObject);
}

That way you don’t need those tedious tags!