Hi, this is probably a “stupid” question that has occurred before on the forum, but I couldn’t find the right search criteria to track down any good answers. So bare with me if you have seen it before.
I want to write a script that i.e disables/enables all MonoBehaviours or a certain Type. This could look something like this:
public class Disabler : MonoBehaviour{
[b]public MonoBehaviour targetBehaviour;[/b]
public void OnDisable() {
Object[] all = Object.FindObjectsOfType([b]targetBehaviour.GetType()[/b]);
foreach (MonoBehaviour mb in all ) {
mb.disabled = true;
}
}
}
The problem with this is that “targetBehaviour” is referencing an instance and not just a type, and I feel that is confusing or “ugly” code. I would like the code to look something like this:
public class Disabler : MonoBehaviour{
[b]public Type targetBehaviourType;[/b]
public void OnDisable() {
Object[] all = Object.FindObjectsOfType([b]targetBehaviourType[/b]);
foreach (MonoBehaviour mb in all ) {
mb.disabled = true;
}
}
}
but when I try this, the “targetBehaviourType” is not shown in the inspector. How would I implement this the right way?
[/code]