Why can I not do a foreach in my List of gameobjects?

I have a list of gameobjects and I want to cycle through the list and disable each object.

foreach (GameObject i in panel) { i.SetActive(false); }```

I am getting the error that I cannot convert char to gameobject. How do I refer to the gameobject?
thank you

Your script works for me:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    public List<GameObject> panel;

    private void Start()
    {
        foreach(GameObject i in panel) { i.SetActive(false); }
    }
}

What does the rest of your script look like? Are you sure the error is on that line?

I see my mistake now, I used “panel” 2 times which caused the error :face_with_spiral_eyes:

public void ChangePanel(string panel)
{
foreach (GameObject i in panel) {
i.SetActive(false);
}
}```

Thanks for testing the code all
1 Like