Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 SuperMasterBlasterLaser · Mar 27, 2014 at 02:51 PM · cameraresolutiongame editor

Different camera views in different devices

Hello.

In my editor I made game with resolution 1280 x 800. I made camera to fill this stage.

That how it looks in my editor: alt text

But when I build *.apk file and installed it into phone with small screen it will look like that: alt text

So it does not show all the stage.

But then I have installed it into device with big screen (Galaxy Note 2). It shows me not only stage with white background but also takes parts that are redundant to player:

http://cs14108.vk.me/c620325/v620325770/170c/ThPlvD-dUQs.jpg

Question: What kind of script code I must to write(in C#) to make it look like in editor, when I run it on every device?

editor.png (217.5 kB)
screenshot_2014-03-27-13-41-57.png (6.3 kB)
Comment
Add comment · Show 3
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 Leuthil · Mar 27, 2014 at 03:16 PM 0
Share

The way Unity handles different sized devices is that it maintains the same view height but sizes the width accordingly. So an iPhone 5S will be extremely narrow whereas an iPad will be wide, but the height you see will be consistent. You can change this behaviour with scripts so that it expands the height ins$$anonymous$$d of the width but at the end of the day you will never get it to be consistent across all devices.

There are a lot of tricks that developers use to get the games to look as consistent as possible across devices with varying aspect ratios, but they are just tricks.

Also for your specific game you want to make sure that in your Android build settings that it is forcing the orientation to be Landscape.

avatar image SuperMasterBlasterLaser · Mar 28, 2014 at 05:54 AM 0
Share

Can you provide one of theese "tricks" ?

avatar image jogidipen · Mar 28, 2014 at 06:25 AM 0
Share

Is Camera Orthographic?

4 Replies

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

Answer by jogidipen · Mar 28, 2014 at 06:29 AM

I given answer for your solution in this link.

link text

just create and apply script on main camera.

Comment
Add comment · Show 4 · 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 SuperMasterBlasterLaser · Mar 28, 2014 at 01:57 PM 0
Share

This worked fine. Thank you

avatar image cregox · Nov 18, 2014 at 07:43 PM 0
Share

This only works for orthographic cameras!

avatar image Danteneo · Sep 30, 2015 at 05:59 PM 0
Share

I had the same problem and that script solved it :) thank you very much :)

avatar image surfuay · Apr 29, 2019 at 08:25 PM 0
Share

does this work when used on an iPad, I've used canvas scaler and my ui is great but the rendering my intractable elements do not move with canvas scaler

avatar image
3

Answer by aqib · Mar 28, 2014 at 06:46 AM

I hope this will help you out. Add this script to main camera. You can recalculate the ratio if you want.

 using UnityEngine;
 using System.Collections;

 public class FixedRatio : MonoBehaviour {

     // Use this for initialization
     void Start () 
     {
         // set the desired aspect ratio (the values in this example are
         // hard-coded for 16:9, but you could make them into public
         // variables instead so you can set them at design time)
         float targetaspect = 1280.0f / 800.0f;
     
         // determine the game window's current aspect ratio
         float windowaspect = (float)Screen.width / (float)Screen.height;
     
         // current viewport height should be scaled by this amount
         float scaleheight = windowaspect / targetaspect;
     
         // obtain camera component so we can modify its viewport
         Camera camera = GetComponent<Camera>();
     
         // if scaled height is less than current height, add letterbox
         if (scaleheight < 1.0f)
         {  
             Rect rect = camera.rect;
         
             rect.width = 1.0f;
             rect.height = scaleheight;
             rect.x = 0;
             rect.y = (1.0f - scaleheight) / 2.0f;
         
             camera.rect = rect;
         }
         else // add pillarbox
         {
             float scalewidth = 1.0f / scaleheight;
         
             Rect rect = camera.rect;
         
             rect.width = scalewidth;
             rect.height = 1.0f;
             rect.x = (1.0f - scalewidth) / 2.0f;
             rect.y = 0;
         
             camera.rect = rect;
         }
     }
 }
Comment
Add comment · Show 2 · 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 SuperMasterBlasterLaser · Mar 29, 2014 at 05:25 AM 0
Share

This is pretty fine solution too. However, when you try to launch game in device with higher resolution, it shows black lines.

avatar image izosimova · Sep 21, 2018 at 07:20 AM 0
Share

Perfectly working for me. Thanks a lot!

avatar image
0

Answer by ivomarel · Mar 28, 2014 at 06:46 AM

I would recommend using a plugin such as NGUI for your UI. NGUI uses something called anchoring, which can (for example) anchor your object to the top right corner, so they always stay there, no matter the resolution.

For other tricks, I'd recommend creating a background around your game that repeats itself (in case of orientations that are too wide/too high). I use this for a platform runner, where the width is always the same, but based on the aspect ratio, the player sees less/more sky.

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 MrGuardianX · Oct 05, 2016 at 02:03 PM 0
Share

It is not wise to use UI solution for actual gameplay since it adds lots of overhead.

avatar image
0

Answer by gabigarciagar · Oct 21, 2018 at 05:56 PM

I have added such script implemetation to my game but I still have 1 problem. Because of the images resize, the canvas resize doesnt fit the real game screen. See pictures as example:

Before playing I force free aspect and the canvas resize to fill the full size of the real screen alt text Then I press play and the game resize with the camera script but the canvas remains the same alt text

¿Who can alfo fix this? Thank you


before-playing.jpg (77.6 kB)
playing.jpg (64.0 kB)
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

28 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

Related Questions

Orthographic Static 2D Background - IOS/Iphone 3,4 & 5 1 Answer

Using 16:9 ratio but Resolution in Game is 1366x595 2 Answers

How to make my game widescreen? 3 Answers

2D Game. Screen, Camera and coordinates. 0 Answers

Camera Distortion effect needed improve (SOLVED) 2 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