
Destruir
Tutorial
Beginner
+0XP
5 mins
157
Unity Technologies

Cómo se usa la función Destroy () (destruir) para remover GameObjects y componentes durante runtime.
Este tutorial está incluido en el proyecto Scripting para principiantes.
Previo: Interpolación linear
Siguiente: GetButton y GetKey
Languages available:
1. Destruir
DestroyBasic
using UnityEngine;
using System.Collections;
public class DestroyBasic : MonoBehaviour
{
void Update ()
{
if(Input.GetKey(KeyCode.Space))
{
Destroy(gameObject);
}
}
}DestroyOther
using UnityEngine;
using System.Collections;
public class DestroyOther : MonoBehaviour
{
public GameObject other;
void Update ()
{
if(Input.GetKey(KeyCode.Space))
{
Destroy(other);
}
}
}DestroyComponent
using UnityEngine;
using System.Collections;
public class DestroyComponent : MonoBehaviour
{
void Update ()
{
if(Input.GetKey(KeyCode.Space))
{
Destroy(GetComponent<MeshRenderer>());
}
}
}