- Home /
Question by
ansheng · Jun 12, 2014 at 03:26 AM ·
startload sceneawakeconstructororder-of-execution
when loading a scene, the execution order is load->constructor->finishfunction->awake->start?
This is under scene 1:
int life = 1;
void Start(){
life = 2;
}
In another scene, I have a button with this function:
OnMouseDown(){
Application.Load("Scene1");
//use static variable Player to access int life;
Player.life = 3;
}
So when I click the button, my life will be first equals to 1, then 3, then 2. Is this right?
It will load the scene -> Constructor ->finish the OnMouseDown function -> Awake -> Start?
Comment
Answer by legion_44 · Jun 12, 2014 at 04:30 PM
No it won't. So, all operations are blocked until unity finish loading scene. Then it will call Awake() (cuz it will set active all GOs) and then Start() on all MonoBechaviours, then You will be able to use OnMouseDown method to change players life. Also have in mind that Awake() is called every time You will set gameobject to active.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151340im_/https://answers.unity.com/themes/thub/images/avi.jpg)