Disabling and Removing Components During Gameplay
You won't have access to the checkbox and menus in the editor while the game is playing, but you might want to turn on and off or remove components.
Enabling and Disabling Components
In the examples below, the following variables are used:
Use the boolean value .enable or turn on components.
Example of turning on the collider on a game object:
Example of turning off the collider on a game object:
Removing Components
Use the Destroy() function to remove components. Go to the link below for more information.
Using the Destroy() FunctionAvoiding Errors
You will get an error if you try to enable, disable, or remove a component that is not there.
You can check to see if a component is there by using this script.
Example of checking for a Rigidbody component:
Accessing Components Through ScriptsCreating Custom Components and Scripts
Last updated