Skip to main content
added explanation
Source Link
Charly
  • 752
  • 3
  • 11

Solution

Try replacing your Component type to a MonoBehavior.

Then script.enabled = false shouldwill work.


Explanation

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.


Resources

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

Try replacing your Component type to a MonoBehavior.

Then script.enabled = false should work.

Solution

Try replacing your Component type to a MonoBehavior.

Then script.enabled = false will work.


Explanation

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.


Resources

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

Source Link
Charly
  • 752
  • 3
  • 11

Try replacing your Component type to a MonoBehavior.

Then script.enabled = false should work.