I'm doing a Spce Invaders, where I have different types of enemies with their respective colors (green, yellow and blue) Every 15 seconds an Enemy Ship is instantiated that can bring any of the colors of the enemies mentioned above. If I destroy the enemy ship and it is yellow, ALL the enemies should be destroyed yellow, and so on with the other colors.
I found a small solution and it is this:
But my problem, is that I do not know how to instantiate the function that leads that foreacha, without having to use an update.
Does anyone imagine how to solve this in a better way?
Any feedback is welcome!
foreach (var w in invaderList)
{
var d = invaderList.Find(f => f.tag == "Invader");
Destroy(w);
}
Exactly, that works for me. The issue is HOW I run that method so that it goes through the entire list.
For example, if I want the Mother Ship, when receiving a shot, call the method to go through the list and verify WHAT is the tag that should be deleted. But in doing so, he can not get into the foreach. And when I want to do it with a coroutine, it tells me that it can not because the object is not active.
This is located on the Mother Ship:
//La nave al impactar con el proyectil del jugador
//llama al método que recorre las listas de los invaders
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "PlayerProjectile")
{
m_Boss.DestroyMultipleInv();
Destroy(gameObject);
}
}
This is found in the Mother Ship Manager:
//Recorre la lista y busca por tag
//qué invader destruir
public void DestroyMultipleInv()
{
foreach (GameObject inv in invaderList)
{
if (inv.tag == "Invader")
{
Destroy(inv);
}
}
}