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
1
Question by minhthinh · Nov 13, 2013 at 10:22 PM · camerascreendesign

Make unity camera appear all screen width

Hi all, When you design on unity (for android), it don't care about the screen width. It show any thing appear on the screen height of camera. But I want it base on the screen width, not screen height.I want to show anything that appear on the screen width of camera. Any solution for it. Thanks.

Comment
Add comment · Show 4
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 PhilRousse · Nov 13, 2013 at 10:52 PM 0
Share

What is the platform you are developping for?

avatar image minhthinh · Nov 13, 2013 at 11:21 PM 0
Share

I'm making a game for Android(tablet).

avatar image BeardOfFury · Nov 13, 2013 at 11:53 PM 0
Share

Are you using an orthographic camera?

avatar image minhthinh · Nov 13, 2013 at 11:55 PM 0
Share

Yes, I'm using orthographic camera.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by BeardOfFury · Nov 14, 2013 at 12:08 AM

For this you need to define what width you want your world to be (Let's say 800 units long). After that you need to get the current aspect ratio of the camera. Calculate the camera height based on the world width and aspect ratio of the camera, then apply to the orthographic size.

 float aspectRatio = (float)Screen.width / (float)Screen.height;
 float cameraHeight = WORLD_WIDTH / aspectRatio;
 
 camera.orthographicSize = cameraHeight/2f;

The reason we use half the desired camera height for the orthographicSize is because that's what the orthographicSize actually is:

orthographicSize

This should leave everything centered and lock the camera to your world width while different devices show more or less vertical height. If you want your camera to always be at the bottom of the level you'll need to adjust the camera's vertical position.

Hope this helps.

Comment
Add comment · Show 6 · 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 minhthinh · Nov 14, 2013 at 12:31 AM 0
Share

I don't understand the WORLD_WIDTH.But when I make WORLD_WIDTH=20, it work. (I have tested on device with resolution 1024*768)

avatar image BeardOfFury · Nov 14, 2013 at 12:34 AM 0
Share

WORLD_WIDTH was only meant to represent whatever you wanted WORLD_WIDTH to be (in your case 20) So that works for you now?

avatar image minhthinh · Nov 14, 2013 at 12:39 AM 0
Share

I have just tested only one device. I will test more with another resolutions. By the way, how can I calculate the WORLD_WIDTH size?

avatar image BeardOfFury · Nov 14, 2013 at 08:10 AM 0
Share

World width can be whatever you want it to be. It's literally just the horizontal size of the world you want to define.

avatar image minhthinh · Nov 14, 2013 at 10:54 AM 0
Share

Thanks BeardOfFury so much. It work.

Show more comments

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

18 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

Related Questions

Keep the multiple players within the screen 2 Answers

Multiple cameras such as in MarioCart 1 Answer

Can the Camera be Positioned on the Game Screen through code? 0 Answers

Fixed width, relative height, on different aspect ratio screen? 4 Answers

Viewport to World Coordinates 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