1 using UnityEngine; 2 3 [ExecuteInEditMode] //添加腳本、啟動、Stop的時候執行Awake() Start() 4 public class test : MonoBehaviour 5 { 6 [SerializeField] 7 int val; 8 void Awake() 9 { 10 Debug.Log("Awake()"); 11 } 12 13 void Start() 14 { 15 Debug.Log("Start()"); 16 } 17 18 #if UNITY_EDITOR 19 //啟動的時候執行兩次,Stop的時候執行一次,組件數值改變的時候執行一次 20 void OnValidate() 21 { 22 Debug.Log("OnValidate()"); 23 } 24 #endif 25 26 }