Cómo habilitar y deshabilitar componentes
Tutorial
·
Beginner
·
+0XP
·
5 mins
·
(245)
Unity Technologies

Cómo habilitar y deshabilitar componentes a través de un script durante el runtime.
Este tutorial está incluido en el proyecto Scripting para principiantes.
Previo: Matemáticas para vectores
Siguiente: Cómo activar GameObjects
Languages available:
1. Cómo habilitar y deshabilitar componentes
C# Enabling and Disabling Components in Unity! - Beginner Scripting Tutorial
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;
}
}
}