---
title: "Enabling and Disabling Components"
content_type: tutorial
url: "https://learn.unity.com/tutorial/enabling-and-disabling-components?language=en"
language: en
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2021.3"
supported_unity_versions:
  - name: "2021.3"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2021.3"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/habilitar-y-deshabilitar-componentes.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/konponentonoyou-xiao-hua-towu-xiao-hua-nitsuite.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/keomponeonteu-hwalseonghwa-mic-bihwalseonghwa.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/qi-yong-he-jin-yong-zu-jian.md?language=zh-cn"
last_updated: "2026-10-07T22:05:46.000Z"
---

# Enabling and Disabling Components

Learn to enable and disable components via C# scripts during runtime as part of the Beginner Scripting project.

How to enable and disable components via script during runtime.

Previous: [Vector Maths](https://learn.unity.com/tutorial/vector-maths?projectId=5c8920b4edbc2a113b6bc26a)

Next: [Activating GameObjects](https://learn.unity.com/tutorial/activating-gameobjects?projectId=5c8920b4edbc2a113b6bc26a)

## 1. Enabling and Disabling Components

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/eed2c14f-7a90-4c40-9bcd-37c5ecd5c959_U_Beginner_10_EnablingandDisablingComponents.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20220104/75f81622-3520-47ef-8b1d-8a7a08cf1f2b_B_10_Enabling_and_Disabling_Components_V5.0.vtt))

```csharp
using UnityEngine;
using System.Collections;

public class EnableComponents : MonoBehaviour
{
    private Light myLight;
    
    
    void Start ()
    {
        myLight = GetComponent<Light>();
    }
    
    
    void Update ()
    {
        if(Input.GetKeyUp(KeyCode.Space))
        {
            myLight.enabled = !myLight.enabled;
        }
    }
}
```
