As stores gameObject-s, what would the destruction go?

Require keeps a list of enemies and the destruction of the enemy to remove it from the list (automatic/manual). How best to store? I did through enemes List, but the destruction of the enemy object is not removed from the list, tried to remove through enemes.Remove(item) - gives an error. How best to implement?
June 10th 19 at 15:09
2 answers
June 10th 19 at 15:11
Solution
You need to do so:
private List<enemy> enemies = new List<enemy>();

private void DestroyEnemy(Enemy enemy)
{
enemies.Remove(enemy);
Destroy(enemy.gameObject);
}</enemy></enemy>

If you destroy the gameObject and then trying to throw out of the list, it could happen nulref due to the fact that the component is already destroyed.
Thank you, first I destroy the object and then delete it from the sheet - maudie1 commented on June 10th 19 at 15:14
Yes, I should have brought a method to remove an object from the sheet and quickly found the error, but other than that I wanted to learn how to best implement(using the array sheet or something else). - maudie1 commented on June 10th 19 at 15:17
A sheet is more comfortable to use, something other wise I don't see the point. - litzy commented on June 10th 19 at 15:20
June 10th 19 at 15:13
Once the part is based on C# wrote half about the game:
I did through enemes List, but the destruction of the enemy object is not removed from the list

Here is what it means?

As the enemy is "destroyed" from the list - show method of destruction?
What error gives?
As you know that the object is not removed?

Find more questions by tags Unity Game Engine.NETC#