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 zeus911 · Mar 16, 2017 at 08:28 PM · cameracanvasstretching

Flexible resolution

Dear all,

I have a few months of experience with Unity. Usually I'm able to find solutions on the internet to my issues quite fast, but my current problem seems to keep me up for a week now. Thus my first ever question.

I simply want my 2D game/orthographic camera to change its resolution to perfectly fit any screen size by stretching (see first picture). I understand in certain games this would ruin the experience but the kind of games I'm trying to create will be fine with some deformation. This weird resolution is just for demonstration purposes. alt text I have read countless posts and tried quite some scripts but at the end didn't find a solution that would achieve this. In other engines I worked with earlier this was a very simple setting on the camera, so I have a feeling this should be doable without much complexity. Definitely without placing every object by script that changes their size one by one to fit the screen.

The latest canvas + camera + script setup I'm trying you can see on below picture. The simple script attached to the camera is this:

 Camera.main.aspect = 12f/20f;

In this case the problem is with the panels being limited by the camera while other images finally resize as desired. Ultimately nothing worked well. Could you help me with a solution please? Thanks. alt text

question1.png (98.6 kB)
question1b.png (15.8 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by zeus911 · Mar 18, 2017 at 01:43 PM

I ended up putting this script into the panel:

 void Start () {
     RectTransform rt = this.GetComponent<RectTransform> ();
     if (Screen.width < 1200) {
         rt.sizeDelta = new Vector2 (1200 - Screen.width, 0);
     } else {
         rt.sizeDelta = new Vector2 (-1200 + Screen.width, 0);
     }
 }

1200 being the original resolution width. So this way the panel will always auto adjust to the current screen at start. With the following setup on the canvas: Screen space - Camera. Match height at 1.

Still this is not a great solution, just a work around. Let me know if someone has an easier solution for making games auto adjust for any resolution. Thanks

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to programmatically scale a canvas element to always be touching another moving canvas element 1 Answer

Why canvas set to Screen Space - Overlay doesn't cover entire screen 0 Answers

Looking for picture in picture effect using Canvas Elements and Cinemachine follow target 0 Answers

How to match a WorldSpace Canvas to Camera's viewport? 0 Answers

world canvases z fighting or rendering in the order when camera moves around 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