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 BzlZavLed · Oct 11, 2014 at 03:51 AM · sizepixelconsole

Hi every one, , not how to rescale an object.

i need to know how to obtain the size of an object in pixels, something like gameobject cube 234x123 pixels may be it is easy but i dont know how to do it, i need a script to get the size in pixels of a cube or a botton preferably, and show it in the unity console, it is because i need to know the measures of the textures i need to put in the box or button so that the texture looks good and not to pixeled. i found here some code like this:

  [MenuItem("Window/ShowSize")]
 static void Init()
 {
     // Get existing open window or if none, make a new one:
     ShowSize sizeWindow = new ShowSize();
     sizeWindow.autoRepaintOnSceneChange = true;
     sizeWindow.Show();
 }
 
 void OnGUI () {
     GameObject thisObject = Selection.activeObject as GameObject;
     if (thisObject == null)
     {
         return;
     }
     
     MeshFilter mf = thisObject.GetComponent(typeof(MeshFilter)) as MeshFilter;
     if (mf == null)
     {return;}
     
     Mesh mesh = mf.sharedMesh;
     if (mesh == null)      
     {return;}
     
     Vector3 size = mesh.bounds.size;
     Vector3 scale = thisObject.transform.localScale;
     GUILayout.Label("Size\nX: " + size.x*scale.x + "   Y: " + size.y*scale.y + "   Z:              " + size.z*scale.z);
 }

but this just give me the scale of the object in a show size windows, and that doesn't work for me. thanks a lot by the way, im new in unity3d edition =)

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 robertbu · Oct 11, 2014 at 03:54 AM

The pixel size of an object with a perspective camera varies based on the distance from the camera. In addition, as you change the resolution of the app (as would happen when moving from one mobile device to another), the pixels also change. Typically if you have a specific device and are looking for pixel perfect, you do it in reverse...you pick a pixel size for the texture then setup the environment to display it at or near pixel perfect. If you really want to know the pixel size of an object there is some code in this answer:

http://answers.unity3d.com/questions/651090/get-width-of-2d-game-object.html

Note this calculates the bounds of the mesh of the object, so the results will depend on the rotation of the object. So for example, if you wanted the pixel size for the bottom of the cube, the bottom would need to be axes aligned and facing an axes aligned camera.

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

2 People are following this question.

avatar image avatar image

Related Questions

Unity 5.4.1p4 No longer outputting Asset Sizes after build? 0 Answers

Rect Transforms not scaling the same? 1 Answer

About how many pixels does the average user need before they can efficiently see and tap an object? 1 Answer

How I get sizeof pixels of object 1 Answer

Question About Terrain 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