I want a Gameobject to delete itself and a ifferent Gameobject with the tag 'Card' The Script is attached to both of them, so i expected it to work for both, but just one of them does it. I used this code The Code is called when i drop the Card so only one of the cards runs the code at a time
Destroy(gameObject);
Destroy(GameObject.FindWithTag("Card"));
I also tried adding
gameObject.transform.SetAsLastSibling();
to see if it would change anything, but it didn't
I fixed it by creating an array with the gameObjects that i want to destroy and then destoying them in order
GameObject[] destroy = GameObject.FindGameObjectsWithTag("Card");
for (var i = 0; i < destroy.Length; i++)
{
Destroy(destroy[i]);
}