0
\$\begingroup\$

I meet an issue that if I use 1024x768 resolution to run my game, the position(not local position) of the canvas is -1 in z axis. On the other hand, with resolution of 1136x640, the position is -5 in z axis(I never use code or anything to change its position). Is there any reason to cause this issue?

\$\endgroup\$
5
  • \$\begingroup\$ Can you share how you found out about this? Is the canvas just a UI Canvas? How do you know the Z position? From the inspector? Or only when you build the game? \$\endgroup\$ Commented Jul 17, 2018 at 10:42
  • 2
    \$\begingroup\$ Do you have a canvas scaler script in play? \$\endgroup\$
    – DMGregory
    Commented Jul 17, 2018 at 10:56
  • \$\begingroup\$ I printed position's x,y and z in run-time. And I have a canvas scaler script in play. \$\endgroup\$ Commented Jul 17, 2018 at 12:04
  • \$\begingroup\$ Try using an orthographic camera, see if the issue is still there. (I'm thinking it has to do with the perspective camera and how the canvas scaler is interacting with it.) \$\endgroup\$ Commented Jul 17, 2018 at 13:13
  • \$\begingroup\$ orthographic camera doesn't have this issue, I tried \$\endgroup\$ Commented Jul 17, 2018 at 14:21

1 Answer 1

1
\$\begingroup\$

you can set the canvas scaler to a constant pixel or physical size rather than scale with screen size. Set the panel to stretch and then you can set the pixels from each edge and it will fix your issue. enter image description here

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ I set it to constant physical size mode and it's working! \$\endgroup\$ Commented Jul 18, 2018 at 1:54
  • \$\begingroup\$ But why it's working? \$\endgroup\$ Commented Jul 18, 2018 at 2:30
  • \$\begingroup\$ @OtakuFitness Constant Pixel Size makes UI elements retain the same size in pixels regardless of screen size, while Scale WithScreenSize makes UI elements bigger the bigger the screen is. \$\endgroup\$
    – user115399
    Commented Oct 27, 2018 at 7:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .