Skip to main content

Unity3D Scripting API #10: OnDestroy() ⚔️

By February 1, 2021February 14th, 2021No Comments
Unity3D Scripting API

⭐ 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");


Leave a Reply