Enabling and Disabling Components
Tutorial
Beginner
5 Mins
Overview
Overview
You have completed 0% of this Tutorial.
1.
Enabling and Disabling Components
Summary
How to enable and disable components via script during runtime.
This tutorial is included in the Beginner Scripting project.
Previous: Vector Maths
Next: Activating GameObjects
Topics we'll cover
Language
English
Recommended Unity Versions
4 and Above
Tutorial
Enabling and Disabling Components
1.
Enabling and Disabling Components

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; } } }