- Home /
Positioning on Z-axis messed up in Android build
(Aaaaagh, I just typed this whole question and then I signed in and lost all the text. Really frustrating.)
I have a scene with a Background quad (Z = 0) which is darkgrey, and a parent GameOver Screen with some sprites which makes up a Game Over screen. (Also some other GO's, but they aren't relevant)
To toggle the GameOver screen, I simply change the Z value of it to hide it behind the Background quad if I don't need it. In the editor with the Standalone as platform, it is working fine and I have no problems whatsoever. However, if I change the platform to Android, the GameOver screen appears in front of the Background, see this image:
This is also the case if I deactivate all the scripts, and it was also the case when I wrote a script attached to the GameOver screen which said:
void Update () { transform.position = new Vector3(0, 0, 20); }
The GameOver screen appears in front of the background, while it shouldn't. What is causing this?
Answer by M-Hanssen · Apr 18, 2016 at 02:36 PM
Changing Z positions is into the way to build UI's in Unity.
At least not when using Camera render mode in you Canvas.
In default Canvas renderMode the Z order as you describe it, is simply controlled by the order inside the hierarchy. Try to move background below GameOver screen :-)
Thanks for your answer. However, changing the order inside the hierarchy didn't help. Also it might be worth noting that the GameOver Screen isn't a canvas, it's just an empty GameObject with sprite Objects as children.
I solved the Game Over screen problem by simply positioning it at x = 15; y = 15 to keep it out of the way. However, I ran into a different problem which is that two spheres - the objects controlled by the player - should appear in front of some obstacle quads. They do in the editor when I run it.
However, they do not appear in front of the obstacles on my Android device. They will appear behind some of the obstacle quads (they are prefabs, but I checked that they have the same Z value), while still in front of others.
I'm sure that I could figure it out somehow if I knew what was causing this, but I don't actually know. On the editor, everything works as normal, but on the Android device, only some objects appear behind others. Do you have any idea, or should I post this in a seperate question?
Your answer

Follow this Question
Related Questions
Unity2D quads not appearing in front of other quads in Android build 1 Answer
Android app: app icon appears in game screen; please help!!! 0 Answers
How to define which Android API level should I target for Minimum and Target? 1 Answer
Android build not working properly 0 Answers
How to port game on android wear ? 2 Answers