Unity 生命周期方法调用时间

1、Awake(),最早调用,只调用一次

2、OnEnable(),组件激活后调用,在Awake()后会自动调用一次,接下来如果再次激活组件还会继续调用

3、Start(),在Update()之前调用一次,在OnEnable()之后调用,可以在此设置一些初始值

4、FixedUpdate(),固定时间调用,每次调用与上次调用的时间间隔相同

5、Update(),帧率调用方法,每一帧调用一次,所以每次调用与上次调用的时间间隔可能不相同

6、LataUpdate(),在Update()每次调用完一次后,紧跟着调用一次

7、OnDisable(),与OnEnable()相反,组件关闭时会调用,可调用多次

8、OnDestroy(),被销毁后调用一次

在这里插入图片描述

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test : MonoBehaviour
{
    
    
	private void Awake()
	{
    
    
        Debug.Log("Awake");
	}

	private void OnEnable()
	{
    
    
		Debug.Log("OnEnable");
	}
	// 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 FixedUpdate()
	{
    
    
		Debug.Log("FixedUpdate");
	}
	private void LateUpdate()
	{
    
    
		Debug.Log("LateUpdate");
	}
	private void OnDisable()
	{
    
    
		Debug.Log("OnDisable");
	}
	private void OnDestroy()
	{
    
    
		Debug.Log("OnDestroy");
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_45972052/article/details/130994887