Games that develop mobile platforms with unity inevitably encounter screen resolutions

Source: Internet
Author: User

Welcome to Unity Learning, unity training, Unity Enterprise training and education, there are many u3d resources, u3d training videos, u3d tutorials, u3d FAQs, u3d Project source code, "Dog Planing Learning Network" Unity's Ultimate Academy, dedicated to building the industry unity3d training, Learn the first brand.
games with Unity to develop mobile platforms inevitably encounter screen resolution issuesdifferent resolutions will cause the normal UI to get messy .we know that in unity it is possible to take a plane as a background UI that is drawn in the position closest to the camera and can be thought of as being drawn on the camera.Therefore, differences in resolution can cause errors in the location and size of the UI
we can use a plane to simulate the button and put it in world space, although it solves the problem of location and size, but the problem is also a lot of difficulties to maintainso we need to scale the UI according to the size of the screen.If there is a button is this, and the current 480x854 resolution is not a problem, if changed to 600x1024 or other resolution, you will find the location and size are not correct
  1. function Ongui ()
  2. {
  3. if (GUI. Button (Rect (screen.width-200, screen.height-100, up, up), "Start"))
  4. {
  5. DoSomething
  6. }
  7. }
  8. Copy Code
Copy Code
so we move and scale the UI proportionally.
  1. Original Screen Size
  2. var m_fscreenwidth:float = 480;
  3. var m_fscreenheight:float = 854;

  4. Scale factor
  5. var m_fscalewidth:float;
  6. var m_fscaleheight:float;

  7. function Awake ()
  8. {
  9. M_fscalewidth = parsefloat (screen.width)/m_fscreenwidth;
  10. M_fscaleheight = parsefloat (screen.height)/m_fscreenheight;
  11. }

  12. function Ongui ()
  13. {
  14. if (GUI. Button (Rect (screen.width-200 * m_fscalewidth, screen.height-100 * m_fscaleheight, * m_fscalewidth, * m_fscale Height), "Start")
  15. {
  16. DoSomething
  17. }
  18. }
  19. Copy Code
Copy Code
If you have more UI controls, it's obviously not necessary to control the size of each one .The matrix is used to implement
    1. Gui.matrix = Matrix4x4.trs (Vector3 (0, 0, 0), quaternion.identity, Vector3 (M_fscalewidth, M_fscaleheight, 1));
Copy CodeThis makes it easy to scale the position and size of the button in proportion

Disclaimer: This document is from the "Dog Planing Learning Network" community, is the Netizen self-published Unity3d study articles, if there is any content violated your relevant interests, please communicate with the official, we will deal with the real-time.
More Highlights:Www.gopedu.com

Games that develop mobile platforms with unity inevitably encounter screen resolutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.