How can I disable every object in the scene besides specific ones that that I drag into an array. Right now I am coding every single object that I don’t want disabled and this is not efficient and will not work when I have objects in some scenes, but different objects in different scenes. I can’t used tags or layers because I already am. Any ideas? Basicly what I am doing is I have the game scene. Once the level is complete disable everything but these few objects to display then level exiting scene where it shows there stats and acheivements.
if theObjects is your GameObject array which you don’t want to disable, then you could use:
GameObject[] allObjects = FindObjectsOfType<GameObject>();
List<GameObject> objectsToDisable = new List<GameObject>(allObjects);
foreach (GameObject a in allObjects) {
foreach (GameObject b in theObjects) {
if (a.name == b.name)
objectsToDisable.Remove(a);
}
}
foreach (GameObject a in objectsToDisable)
a.SetActive(false);
Note that this isn’t the most optimized solution, but it does the trick.