Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Swad · Dec 29, 2015 at 05:16 PM · c#scalescreen

Why my Scale Script don't work ?

Hello, I will become crazy because my script don't work ! Why ? I am using resolution of 320 * 480 and i want save the same proportionality for my Sprite2D. (0.04 horizontaly and 0.05 verticaly)

 using UnityEngine;
 using System.Collections;
 
 public class Scaling : MonoBehaviour {

     void Update () {
         float factor1 = (Screen.width/320)*0.04f;
         float factor2 = (Screen.height/480)*0.05f;
         transform.localScale = new Vector3(factor1, factor2, 0);
     }
 }
 

Please, help me, thanks.

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
0

Answer by jmonasterio · Dec 29, 2015 at 06:39 PM

Can't tell from the question what you're expecting, but I suspect the problem is a rounding error caused by division by an integer (you lose the floating point precision). Try adding .0f to the 320 and 480.

 float factor1 = (Screen.width/320.0f)*0.04f;
 float factor2 = (Screen.height/480.0f)*0.05f;

If this doesn't resolve the problem, try adding this at line 9, so you can see what numbers are being calculated. Maybe post the numbers you're seeing, and what numbers you want.

 print( factor1);
 print( factor2);
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 Swad · Dec 29, 2015 at 07:20 PM 0
Share

Hi, Hi, thanks for the help, but I discover another problem : why my using resolution is (305 * 458) whereas I select (640*960) ? I choose this resolution because it's double of my default resolution (320*480), so logicly : Scale x = 0.08 and Scale y = 0.1. (defaults scales with (320*480) : x = 0.04f and y = 0.05.! [Image1]

When i lauch the game with (305 * 458) resolution, it works : [Image2]

But if i choose another resolution , only the scale x is good, scale y don't change : [Image3]

Thanks very much for the help !alt text!

avatar image Swad Swad · Dec 29, 2015 at 07:27 PM 0
Share

The images : i can't submit it in Unity answers ! $$anonymous$$y drive : https://drive.google.com/open?id=0Bwgt9hk4Zo8cNzBJSkdFS3RHYVU

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

53 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 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

What scale value is necessary for get 1\2 part of the original? 1 Answer

Take screenshot with no lags Android 0 Answers

NullReferenceException 1 Answer

Spawning multiple gameobjects with random scales 2 Answers

1 Restart Scene multiple levels. Is this possible? - C# - 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