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