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 brain56 · May 18, 2012 at 08:56 AM · camerapixel

Modify Camera pixelWidth and pixelHeight

How do I modify Camera's read only fields pixelWidth and pixelHeight? I intend to configure my camera to contain 1024 pixels in width and 768 pixels in height. Thanks! :D

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tnetennba · May 18, 2012 at 11:12 AM

Use the screen api:

http://unity3d.com/support/documentation/ScriptReference/Screen

You can use this to get the available resolutions and then call:

http://unity3d.com/support/documentation/ScriptReference/Screen.SetResolution.html

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 tnetennba · May 18, 2012 at 11:17 AM 1
Share

There is also this which you can use to set the pixel rect for the camera http://unity3d.com/support/documentation/ScriptReference/Camera-pixelRect.html

avatar image brain56 · Jun 07, 2012 at 07:08 AM 0
Share

I'm sorry, but that doesn't answer my question. You refer to changing the resolution of the screen, not the camera. I want to change these values:

http://unity3d.com/support/documentation/ScriptReference/Camera-pixelWidth.html

http://unity3d.com/support/documentation/ScriptReference/Camera-pixelHeight.html

Thank you. :D

avatar image hirenkacha · Jun 07, 2012 at 07:19 AM 0
Share

I dont think that it will get modified. These values are read only.

avatar image brain56 · Jun 08, 2012 at 05:02 AM 0
Share

Is that so? Can you recommend a workaround to my problem? I want to use ScreenToViewportPoint() and get an accurate translation given an arbitrary position, but since the values of pixelWidth and pixelHeight are fixed, I can't do it.

avatar image
0

Answer by Zherynn · Oct 15, 2012 at 08:44 PM

If you're still looking for the answer, this worked for me:

 camera.rect = Rect((Screen.width-512.0)/Screen.width,(Screen.height-256.0)/Screen.height,384.0/Screen.width,96.0/Screen.height);

That positions it at 512px left of the right edge and 256px below the top, 384px wide and 96px tall. You can of course adjust all the numbers to whatever you want.

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
avatar image
0

Answer by shadowdiver · Jan 22, 2017 at 09:44 PM

I found a working Solution depends on Zhernn's answer.

     public float cameraWidth = 206f;
     public float cameraHeight = 189f;
 
     // Update is called once per frame
     void Update () {
         // Camera has fixed width and height on every screen solution
         float x = (100f - 100f / (Screen.width / cameraWidth)) / 100f;
         float y = (100f - 100f / (Screen.height / cameraHeight)) / 100f;
         GetComponent<Camera>().rect = new Rect(x, y, 1, 1);
     }

The clue is to change the Rect's x- and y-value as percentage and not the Rect's width and height.

One last Tip:

Pose and scale the camera first with viewport rect and then debug the size with GetComponent().pixelWidth and GetComponent().pixelHeight to get the cameraWidth and camereHeight values.

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
avatar image
0

Answer by AgathoSAreS · Jul 05, 2021 at 07:58 PM

Call me a designer but what about this setting in the Gameview?alt text


unity-set-screen-res.png (26.5 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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get pixeldata from graphics.drawmesh? 0 Answers

How to make camera position relative to a specific target. 1 Answer

Restricting ratio of a 2D Game 2 Answers

Questions about Unity 2D camera setup 1 Answer

Pixel Perfect Camera auto *zoom/scales* on different resolution 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