This function is called when the behaviour becomes disabled.
This is also called when the object is destroyed and can be used for any cleanup code. When scripts are reloaded after compilation has finished, OnDisable will be called, followed by an OnEnable after the script has been loaded.
#pragma strict // Implement OnDisable and OnEnable script functions. // These functions will be called when the attached GameObject // is toggled. // This example also supports the Editor. The Update function // will be called, for example, when the position of the // GameObject is changed. @ExecuteInEditMode public class PrintOnOff extends MonoBehaviour { function OnDisable() { Debug.Log("PrintOnDisable: script was disabled"); } function OnEnable() { Debug.Log("PrintOnEnable: script was enabled"); } function Update() { } }
// Implement OnDisable and OnEnable script functions. // These functions will be called when the attached GameObject // is toggled. // This example also supports the Editor. The Update function // will be called, for example, when the position of the // GameObject is changed.
using UnityEngine;
[ExecuteInEditMode] public class PrintOnOff : MonoBehaviour { void OnDisable() { Debug.Log("PrintOnDisable: script was disabled"); }
void OnEnable() { Debug.Log("PrintOnEnable: script was enabled"); }
void Update() { #if UNITY_EDITOR Debug.Log("Editor causes this Update"); #endif } }