Teaching Newbies since 2014

kauress

  • Home
  • Javascript ❤
    • JavaScript
    • Node.js
  • WebDev Tuts
  • screencasts
  • Resources
  • VR & AR
  • Contact
  • Github
  • Twitter
  • YouTube
  • RSS
  • C++
You are here: Home / Unity3D / Unity3D Scripting API #10: OnDestroy() ⚔️

February 1, 2021 by: Kauress

Unity3D Scripting API #10: OnDestroy() ⚔️

⭐ OnDestroy()
⚔️ Called when a gameObject or component is destroyed
⚔️ Called when current scene or game ends. Or the play mode is exited from.
⚔️ You should de-initialize variables and references inside onDestroy()
⚔️OnDestroy() deletes/destroys the object completely because it won’t be re-used

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

        Debug.Log("Start event");
    }
    void Update()
    {

    }
    void OnDestroy()
    {
        Debug.Log("onDestroy event");


    }
}
Unity3D Scripting API #9: OnDisable() 🛡
Introduction to C# in Unity3D #4: Data Types – 2 🌌

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2021 ·Kauress