问题: 在Unity3D项目中经常会遇到不知道应该把初始化代码写在Awake(), Start()还是OnEnable()函数中.
测试: 直接上代码
using UnityEngine;
public class test_MonoBehaviour : MonoBehaviour
{
public static string pressKey = string.Empty;
void Awake()
{
Debug.Log("-----Awake-----" + pressKey);
}
void Start()
{
Debug.Log("-----Start-----" + pressKey);
}
void OnEnable()
{
Debug.Log("-----OnEnable-----" + pressKey);
}
void OnDisable()
{
Debug.Log("-----OnDisable-----" + pressKey);
}
void OnDestroy()
{
Debug.Log("-----OnDestroy-----" + pressKey);
}
}
using UnityEngine;
public class test_MonoBehaviourCtrl : MonoBehaviour
{
GameObject testDestr