- Home /
Disabling objects in csene
I tried to disable all objects in the scene except for objects that go into an array but I can't work out if anyone can help and figure out what's wrong
public GameObject[] allObjects;
public List<GameObject> objectsToDisable;
void Start()
{
GameObject[] allObjects = FindObjectsOfType<GameObject>();
List<GameObject> objectsToDisable = new List<GameObject>(allObjects);
foreach (GameObject a in allObjects)
{
foreach (GameObject b in objectsToDisable)
{
if (a.name == b.name)
objectsToDisable.Remove(a);
}
}
foreach (GameObject a in objectsToDisable)
a.SetActive(false);
}
Comment
Answer by DroidVision · Aug 16, 2019 at 08:20 AM
If you have the list of objects that you want to disable in "objectsToDisable", then just try this
foreach (GameObject a in objectsToDisable)
{
a.SetActive(false);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
I can't use Rigidbody2D in my scripts, I can't find rigidbody2d in my script 3 Answers
How can i rotate my character smooth using keys ? 0 Answers
How can i check and fire an event when the user look at specific object ? 0 Answers