在unity运行的时候运行Update

2023-05-16,,

我们有时候需要在编辑器模式下运行Update用于处理一些函数,一般情况下Update这个函数必须得在play模式下才会运行,如果我们想让它在编辑器启动的时候就运行呢?

上代码

using UnityEngine;
using System.Collections;
using UnityEditor;


[InitializeOnLoad]
public class Easy2DEditorUpdate {

	// Use this for initialization
	static Easy2DEditorUpdate() {
		EditorApplication.update += Update;
	}
	
	static void Update ()
	{
		//do();
	}
}

这样只要unity是开着的,那么它就会一直调用Update.

《在unity运行的时候运行Update.doc》

下载本文的Word格式文档,以方便收藏与打印。