在游戏运行中动态添加物体(AddComponent)时,会先调用一次Awake
比如:
public class TextA : MonoBehaviour{
Awake(){
Debug.LOg("TextA-Awake");
}
Start(){
Debug.Log("TextA-Start");
}
}
public class TextB:MonoBehaviour{
Start(){
this.gameobject.AddComponent<TextA>();
Debug.Log("添加TextA成功");
}
}
将TextB附在物体上启动打印的结果为:
TextA-Awake;
添加TextA成功;
TextA-Start