- Home /
Turn off all Colliders from Scene
Is there a way to turn off all colliders at once when a certain function is called, or a boolean is set to true?
@DrZ, you should convert your comment into an answer. Up-voted.
Answer by Dr.Z · Sep 08, 2013 at 06:32 AM
No I don't think such a function exist. But you could create one that does what you want. You get all gameObjects using FindObjectsOfType from GameObject, then iterate on the returning objects and finally test if the object have a collider (go.collider), if so you can turn it off ;)
(if you need example of code for iterating on gameObject, I invite you to search on google for something like: unity iterate all gameobject). I hope this helps you a little.
FindObjectsOfType is way more versatile. You can directly search for colliders. There's no need to search for gameobjects first.
$$anonymous$$y opinion, create an array or a list of colliders in which you store them all right from the start. A list would allow you to add new objects at runtime. Then when needed you go through it. Looking for objects at runtime is no good if you look for a lot of them among all objects of the scene.