using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
private void Awake()
{
Debug.Log("唤醒");
}
// Start is called before the first frame update
void Start()
{
Debug.Log("start");
}
// Update is called once per frame
void Update()
{
Debug.Log("update");
}
private void OnEnable() //**的时候被调用
{
Debug.Log("对象**");
}
private void OnDisable()
{
Debug.Log("对象休眠");
}
private void OnDestroy()
{
Debug.Log("对象销毁");
}
}
可以看到输出如下:
awake
相当于是构造函数,gameobject在构造的时候就会调用。
onEnable onDisable
对象在**的时候和休眠的时候被调用
onEnable在awake之后,但是在第一帧之前被调用
start
在对象**之后调用
update
不停的进行循环
onDestroy
对象销毁的时候进行调用