Unity——C#脚本执行顺序

脚本文件内的方法执行顺序

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

public class Move : MonoBehaviour
{
// Unity生命周期-调用方法顺序如下
// Awake,只会执行一次
private void Awake() {
Debug.Log("Awake"); // 相当于Console.WriteLine
}

// 只要激活组件,就会执行一次
private void OnEnable() {
Debug.Log("OnEnable");
}

// Start is called before the first frame update
// 在OnEnable()方法运行之后,只会执行一次
void Start()
{
Debug.Log("Start");
}

// Update is called once per frame
// 每一帧就会调用一次
void Update()
{
Debug.Log("Update");
}

// Update()执行一次,就会执行一次LateUpdate()
private void LateUpdate() {
Debug.Log("LateUpdate");
}

// 每隔固定间隔,就会调用一次 默认0.02调用一次,在Unity中,Project Settings中时间中设置
private void FixedUpdate() {
Debug.Log("FixedUpdate");
}

// (脚本选择)非激活中,调用一次,与OnEnable相反
private void OnDisable() {
Debug.Log("OnDisable");
}

// 脚本组件被销毁时被调用
private void OnDestroy() {
Debug.Log("OnDestroy");
}
}

多个脚本执行顺序设置

image.png

posted @ 2023-06-08 07:54  不爱菠萝的菠萝君  阅读(126)  评论(0)    收藏  举报