How to destroy a arraylist with foreach
<pre><code>GameObject Lightwall;   // It's here we store the name tag 
GameObject LightWalls;  //the name of the tag
Object[] LightWall; 

public GameObject wallPrefab;
Collider2D wall;  // this is the wall which is surrounding the player
Collider2D walls; //had to make a new because of this error `wall' conflicts with a declaration in a child block

Vector2 lastWallEnd;

void OnTriggerEnter2D(Collider2D co)
{
    if (co != wall &amp;&amp; co.tag != "Power Up")
    {
        healthP1--;

        if (healthP1 == 1)
        {
            transform.position = Vector3.zero;

            var Lightwall = GameObject.FindWithTag("LightWalls");
            foreach (var walls in LightWall) //NullReferenceException: Object reference not set to an instance of an object this is the error that i'm getting: Playermovmnet.OnTriggerEnter2D(UnityEngine.Collider2D co)
            {
                Destroy(Lightwall);
            }

        }
</code></pre>

<p>My problem is the code <code>foreach (var walls in LightWall)</code>. I have tried to just use the other wall but this error showed up: <code>wall conflicts with a declaration in a child block</code>. The only way to get rid of it was to make another one that is similar.</p>