OnDestroy方法 很好用的方法 不能忘了它
用一段简单的例子解释一下
这是AA脚本
using UnityEngine;
using System.Collections;
public class AA : MonoBehaviour {
void OnDestroy(){
print("Des A");
}
}
这是CC脚本
using UnityEngine;
using System.Collections;
public class CC : MonoBehaviour {
void Update () {
if(Input.GetMouseButtonDown(1)){
Destroy(GameObject.Find("Cube"));
//GameObject.Find("Cube").GetComponent<AA>().enabled=false;
}
}
}
Cube 自己随便的建一个
运行的结果不难发现 Cube销毁后 执行了 print("Des A");
OnDestroy方法 很好用的方法
最新推荐文章于 2024-10-01 21:22:21 发布