Ever since updating my project from Unity 4.6.2 to Unity 5 I’ve had this issue and it’s been driving me crazy.
Here’s my setup:
I have 2 Canvases, Intro and Game
Initially, the Intro status is active and the game Canvas is disabled.
The Intro Canvas has a button which calls a method that deactivates the Intro Canvas and enables the Game Canvas. (Hitting escape at this point switches them back)
At this point everything works great.
Now here’s my problem. I’m trying to set the positions of some objects on the Game Canvas before it’s displayed. But the positions are not being updated (in a newer version of Unity. This worked fine in 4.6.2)
Now, if I hit escape, setting everything back the way it was and then click the button again suddenly the positions are set as expected. So it does work the second time it’s called, just not the first.
I’ve tried mixing up the order of setting the states and object positions with no luck. I can also set the positions pretty much anywhere else in code and it will work correctly. Just not here where I need it to.
Anyone have any ideas what’s going on here?
public void LeaveIntroScreen(){
guiState = GuiState.Game;
IntroCanvas.SetActive(false);
GameCanvas.enabled = true;
tile[0].transform.position = new Vector3(83.0f,120.0f,0.0f);
}
if(Input.GetKeyUp("escape")) {
if(guiState == GuiState.Game) {
GameCanvas.enabled = false;
IntroCanvas.SetActive(true);
guiState = GuiState.Intro;
}
}