Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MohameDiab · May 09, 2020 at 04:24 AM · resolutionaspect-ratioscreen resolution

How can i make my game matching all Android Mobile Screen?

Hello , Please i feel disappointed really , i can't get clear solution or script or Tutorial for this problem for 10 days.

I build my game in resolution 1280 x 720 and it's awesome. but if i change it by editor to any aspect ratio, the game is not good.

I did Maincanvas with Scale with screen size , screen space - camera.

i add sprite render for background and i write the script to make background the same canvas.

but i can't make all game to be matching with all resolution aspect ratio.
please tell me clear solution for this question:

How can i make my game matching all Android Mobile Screen?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JonnyHilly · May 09, 2020 at 05:07 AM 0
Share

need a bit more information please... is it a 2d game or 3d ? is this a background sky, horizon or something else? a game-board ? For Ui the easiest way is to set a screen space overlay camera set to stretch to fill to the screen edge, then all your other ui, fits inside here, and clamps to the edges. if you need a 3d background, use a skybox on the camera's clear settings. for 2D, just make the backdrop much bigger than the screen. Never assume a fixed size device screen.... all devices are different. please provide some more info

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MohameDiab · May 09, 2020 at 06:44 AM

it's 2D game , iam using Main Canvas and have a many photos inside it like child. Screen Space overly ! not working because when i change aspect ratio ! the images is look different not not like good like 1280 x 720 !

i am beginner but i think it's very hard i wasted time every day for 10 days and more than 10 hours per day in this issue ! i can't get clear solution please help me !

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by JonnyHilly · May 09, 2020 at 09:51 PM

its takes a while to get the hang of the Ui system, its not intuitive but its pretty powerful once you learn it. so here it is in rough.... you'll have to learn about each thing mentioned, or find a demo somewhere that already does it, and copy the structure.....

you already have screen space canvas that is step 1 next build your hierarchy inside that object,... say name it MainParent, and set its rect transform mode to expand to fit... this one will then match the size of your device.... now inside that.... you want a bunch of photos.... maybe you want then in a scroll window ? so make another child object... ad a scroll component. and inside that object... make another child, call it Container.... add a layout component to the container... maybe a gridLayout Component inside the container.... make more objects, each with an "image" component for your photos.... check the checkbox on those images to maintain aspect ratio. setup the scroll component's variable to point to your container.

That much may get you a grid of photos at correct aspect regardless of device.

More tricky stuff....

You may need to use a combination of the following 2 component types to get everything looking perfect.... ContentSizeFitter, and Horizontal, Vertical or Grid LayoutComponent ContentSizeFitter is good to put on a parent, if you want it's size to increase based on the child objects.... ( possibly your scroll rect 'container' object) LayoutComponents control how child objects fit next to each other... say for example you put a grid layout component on your Container. then all the photos would be put into that grid. you can set the size of each grid square in the layout component. ...and the "keep aspect" ratio checkbox will keep your images for being stretched. that should be enough to get you pointed in the right direction.... learn those components and you'll be set.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MohameDiab · May 09, 2020 at 10:18 PM 0
Share

please help me to edit this code the (transform.localscale) is wrong ! can you tell me how to edit it

public class Screenfit : $$anonymous$$onoBehaviour { public int WorkingXorRatio; public int WorkingYorRatio; public bool ChangeX; public bool ChangeY; public bool ChangeXRotated; public bool ChangeYRotated; public Transform $$anonymous$$ainCamera; private int HeightStore; private int WidthStore; private float ratiox; private float ratioy; private float xdistance; private float ydistance; private float newxdistance;

 void Start()
 {
     
     HeightStore = Screen.height;
     WidthStore = Screen.width;

     ratiox = Screen.width * WorkingYorRatio;
     ratioy = Screen.height * WorkingXorRatio;

     if (ChangeX)
     {
         transform.localScale.x = transform.localScale.x * ratiox / ratioy;
         transform.localScale.x = transform.localScale.x * ratiox / ratioy;
         xdistance = this.transform.position.x - $$anonymous$$ainCamera.position.x;
         newxdistance = xdistance * (ratiox / ratioy);
         this.transform.position.x += newxdistance - xdistance;
     }
     if (ChangeY)
     {
         transform.localScale.y = transform.localScale.y * ratioy / ratiox;
         xdistance = this.transform.position.y - $$anonymous$$ainCamera.position.y;
         newxdistance = xdistance * (ratioy / ratiox);
         this.transform.position.y += newxdistance - xdistance;
     }
     if (ChangeXRotated)
     {
         transform.localScale.y = transform.localScale.y * ratiox / ratioy;
         xdistance = this.transform.position.x - $$anonymous$$ainCamera.position.x;
         newxdistance = xdistance * (ratiox / ratioy);
         this.transform.position.x += newxdistance - xdistance;
     }
     if (ChangeYRotated)
     {
         transform.localScale.x = transform.localScale.x * ratioy / ratiox;
         xdistance = this.transform.position.y - $$anonymous$$ainCamera.position.y;
         newxdistance = xdistance * (ratioy / ratiox);
         this.transform.position.y += newxdistance - xdistance;
     }
 }

 

}

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keeping Aspect Ratio without filling screen 0 Answers

Clickable Area on UI buttons get shifted when starting game in aspect ratio that differs from canvas reference resolution 2 Answers

Clamping after forcing aspect ratio 0 Answers

Handling Multiple Resolutions in 2D? 0 Answers

Build game in portrait aspect without blue borders? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges