Answers for "unity on gameobject destroy"

C#
4

how to destroy object in unity c#

// 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);
Posted by: Guest on April-28-2022
-2

destroy gameobject unity

void OnTriggerEnter()
{
    if(PlayerPrefs.GetInt("GotPotion", 0) == 0)
    {
        // You didn't get the potion yet, so get it
        Destroy(gameObject);
        PlayerPrefs.SetInt("GotPotion", 1); // got the potion
    }
}
Posted by: Guest on March-24-2022

C# Answers by Framework

Browse Popular Code Answers by Language