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 ham · Oct 16, 2013 at 02:44 PM · resolutionscalescreen

changing the sprite scale with screen resolution

ok ok i know the rule , search at first

 search();
     if(search == null)
     {
     ask();
     }
 so believe that its nearly an hour or maybe more that im searching but still....

im finishing my project and now i wanna change the scale of my sprites with different monitor resoluttion ive made my sprite with 1368 * 768 that is a 16/9 ratio...there are same questions in forum but whole of them are about gui ..but i havent used from gui elements in my 2d game and ive only used sprites that got transform.localscale not rect.... thanx

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

1 Reply

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

Answer by robertbu · Oct 16, 2013 at 05:41 PM

Given that you are talking about game object in world space, their height will remain constant across all resolutions. So you only have to adjust the width. Given you have the aspect you authored for, the math is simple:

 newObjectWidth = OldObjectWidth * 9.0 / 16.0 * Screen.width / Screen.height;
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 ham · Oct 17, 2013 at 04:03 AM 0
Share

but with your code my newwidth changes even in my origin res 1368* 764 for example

 oldobjectwidth= 130 ;  
 1368/764 = 1.79 
  1.79 * 16 = 28.64 
 130 * 9 = 1170
 1170 / 28.64 = 40 that isnt equal with my oldwidth..!!
avatar image ham · Oct 17, 2013 at 05:13 AM 0
Share

ok , i guess the place of 16 and 9 should be changed , this is my code

 var NewObjectWidth : float ;
     var OldObjectWidth : float ;
     function Start ()
     {
         OldObjectWidth = this.transform.localScale.x ;
         //print (OldObjectWidth);
         NewObjectWidth = ((OldObjectWidth * 16.0) / ((9.0 * Screen.width )/ Screen.height));
         //this.transform.localScale.x = NewObjectWidth ;
         print (NewObjectWidth);
     }
     
     function Update ()
     {
         
     }

but still it doesnt work,,,, maybe i should change the camera size...oah im confused , can anyone tell anything about this or i should solve this by myself

avatar image robertbu · Oct 17, 2013 at 08:08 AM 3
Share

The formula is to first multiply by the inverse of the current aspect ratio and then multiply by the new aspect ratio. You can be a bit more accurate by using the actual resolution since it is not a perfect 16/9.

 newObjectWidth = oldObjectWidth * 764 / 1368 * Screen.width / Screen.height;

Your parentheses change the calculation.

avatar image ham · Oct 17, 2013 at 09:14 AM 0
Share

thanx , my background changes correctly , but the problem is , that some objects that are in corner of screen in my origin resolution , in lower res such 800 * 600 disappear from the camera , now is there a way to position them base on screen resolution , not in world system

avatar image robertbu · Oct 17, 2013 at 06:59 PM 1
Share

You might take a look at viewport coordiantes. They start in the lower left at (0,0), and go to (1,1) in the upper right. So you can use a coordinate like (.15, .15) to put something in towards the lower left. You would use Camera.ViewportToWorldPoint() to convert this coordinate into a world coordinate for the placement of the object. Note you must set the 'z' component of the point to the distance in front of the camera before making the conversion to world coordinates.

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

14 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

Related Questions

How to scale everything with screen size? 4 Answers

GUI adapting to screen resolution? 3 Answers

GUI and Screen Resolution 1 Answer

How to maintain high resolution custom background images for GUI elements on different screen sizes? 0 Answers

[Android] Screen Scaling?! 0 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