• 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 pdrinovac2 · Aug 02, 2015 at 07:28 PM · cameraresolutionpixelratio

Restricting ratio of a 2D Game

I'm working on a game that I want to be the same resolution as a Game Boy Advance game, being only 240x160. Now obviously that would be annoying to play on a computer, so I want to scale the game up. What I want is to limit the camera to seeing 240x160 pixels, but when the game runs, be able to scale up the screen while keeping the ratio (even if I can't keep the ratio perfect, that's okay as long as I can limit the camera but can still scale the game in a window). How would I go about limiting the camera? I'm pretty sure the scaling will be handled by Unity when the game is run.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mtdrume · Aug 02, 2015 at 08:16 PM

Add a black frame to the UI using solid panels to your desired size, ensure you setup anchors to the frame position, whatever you see inside the frame will be the same on every device and platform.

or

setting

 Screen.SetResolution(240, 180, true);

not sure how it will look, true being fullscreen

Comment
Add comment · Show 5 · 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 pdrinovac2 · Aug 05, 2015 at 09:32 PM 0
Share

This didn't seem to do anything, unfortunately. I put it in my camera script and nothing changed.

avatar image mtdrume · Aug 06, 2015 at 02:25 PM 0
Share

ensure you include this in Start() or Awake() or you are calling it. This is for desktop only as mobiles and tablets res generally cannot be changed.

 using UnityEngine;
 using System.Collections;
     
 public class ExampleClass : $$anonymous$$onoBehaviour {
     
 void Start() {
    
 Screen.SetResolution(240, 180, true);
     
 }
     
 }
avatar image pdrinovac2 · Aug 06, 2015 at 04:03 PM 0
Share

I will do so but what file do you recommend I put it in? $$anonymous$$y player, camera, game manager, or make a new file and attach it to an object or the canvas? If I had more time today I would try them all out but today's a busy one lol

avatar image mtdrume · Aug 06, 2015 at 04:37 PM 0
Share

Any object that is present during startup. If you make a new script you could also go to Edit > Project Settings > Script Execution Order to ensure it is the first thing to happen. Also the res does not change in editor, must compile and run to see results. To do it in the editor click the drop down box in the preview that defaults to Free Aspect and then click the + button.

avatar image mtdrume · Aug 06, 2015 at 04:50 PM 0
Share

after a quick test, with full screen enabled, as expected it fills the screen, but at set res. windowed looks better but is tiny, mobile is terrible! If you want something that's smaller like a gameboy but still have quality i would still suggest making a frame.

avatar image
0

Answer by rv0000s · Aug 06, 2015 at 06:08 PM

I found this script from my old project. Maybe this will work

what this script does is crop the camera rect. Just attach this script to the camera.

     public float aspect_ratio_x=9f;
     public float aspect_ratio_y=16f;
 
     void Start() {
         fixaspect ();
     }
     void fixaspect(){
         float targetaspect = aspect_ratio_x / aspect_ratio_y;
         float windowaspect = (float)Screen.width / (float)Screen.height;
         float scaleheight = windowaspect / targetaspect;
         if(scaleheight>=1f) {// add pillarbox
             float scalewidth = 1.0f / scaleheight;            
             Rect rect = GetComponent<Camera>().rect;            
             rect.width = scalewidth;
             rect.height = 1.0f;
             rect.x = (1.0f - scalewidth) / 2.0f;
             rect.y = 0;            
             GetComponent<Camera>().rect = rect;
         }
         else {
             GetComponent<Camera>().rect=new Rect(0,0,1,1);
         }
         //Camera.main.aspect = aspect_ratio_x / aspect_ratio_y;
     }
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to letterbox the screen and have pixel perfection in a 2d game 0 Answers

WebCamTexture, get correct resolution and RATIO. 5 Answers

My Text gets blurry with Pixel Perfect Camera and Upscale Render Textrures Active 0 Answers

How to retain absolute gameobject size in pixels no matter the resolution? 2 Answers

Can I make my 2D game's sprites the exact same amount of pixels no matter what resolution the game is running at? 1 Answer


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