Version: 2017.1

描述

当脚本化对象超出范围时调用此函数。

当对象销毁时也会调用该函数,它可用于任何清理代码。 当编译完成后重新加载脚本时,将调用 OnDisable,并在加载脚本后调用 OnEnable。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnDisable() { print("script was removed"); } }

OnDisable 不能作为协程。