Hi, I’m not new to programming but I am new to unity and c#. I need to deactivate all objects in a specific layer and be able to reactivate them again.
Is it possible to turn off a whole layer? The dream scenario would be something like Deactive(layer); xD But from what I’ve found on the internet that’s not possible.
So I guess I have to store all gameobjects in an array and loop through it deactivating every object in that array. Is this the best solution? If so, how do I do this with c#?
As @whydoidoit suggestion is the fastest. If you don’t want to tag them, @Erich5h5 has a solution here:
FindObjectsOfType() is slow, so you don’t want to be calling it every frame. Note it only finds active game objects. Assuming all of your game object have colliders, then @Bunny83 suggests using Physics.OverlapSphere() which can take a layer parameter. You specify a radius bigger than your scene, and every object is the scene is checked. As with Eric’s solution, only active game objects are found, so you will need to cache the result in order to reactivate.