• Unity
  • Services
  • Made with Unity
  • Learn
  • 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
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Made with Unity
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Output second camera to second screen? 0 Answers

Splitting the game view - part camera, part opaque navigational panel at runtime 1 Answer

Keep GameObject on a corner of the screen 1 Answer

How to make your UI fit any iOS resolution? 1 Answer

Polygons clipping at edge of screen 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges