unity – disabling or enabling a public component


Try replacing your Component type to a MonoBehavior.

Then script.enabled = false will work.


The Component is the base class for anything that can be attached to a gameobject, it is very barebones, and does not support enabling/disabling.

The MonoBehavior class inherits all the functionality of Component but adds some extra features. For your purposes, what’s important is that it supports enabling/disabling via scripts or the inspector.


Here’s a more detailed SO answer which explains the differences between Component, Behavior and Monobehavior if you’re interested.