
using UnityEngine; [ExecuteInEditMode] //添加脚本、启动、Stop的时候执行Awake() Start()
public class test : MonoBehaviour
{
[SerializeField]
int val;
void Awake()
{
Debug.Log("Awake()");
} void Start()
{
Debug.Log("Start()");
} #if UNITY_EDITOR
//启动的时候执行两次,Stop的时候执行一次,组件数值改变的时候执行一次
void OnValidate()
{
Debug.Log("OnValidate()");
}
#endif }