xxxxxxxxxx
using UnityEngine;
public class ExampleScript : MonoBehaviour
{
public GameObject objectToDestroy;
void Start()
{
// Destroy the GameObject after 3 seconds
Destroy(objectToDestroy, 3f);
}
}
xxxxxxxxxx
// To remove a GameObject use the function 'Destroy()'
Destroy(gameObject);
xxxxxxxxxx
// To remove a GameObject attached to this script instantly
Destroy(gameObject);
// To remove a GameObject attached to this script
//in certain time (5 seconds for this example)
Destroy(gameObject,5);