Hello!
I was wondering if there was any way to store any kind of component inside a single variable.
I would like to have a script that disables any component inside the OnDisable() method just setting the property .enabled to false.
Is it possible? Thanks!
Behaviour behaviours = GetComponents();
foreach(var b in behaviours)
b.enabled = false;
However, GetComponents<Behaviour>()
won’t retrieve components such as colliders (because they are not Behaviours) and you will need to do it separately
Collider[] colliders = GetComponents<Collider>();
foreach(var c in colliders )
c.enabled = false;