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
1
Question by ganesh-mune · May 09, 2013 at 10:51 AM · scale

Can I get the size ( height and width) of a plane in pixels?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Rabwin · May 09, 2013 at 11:05 AM

Yes, but the math is fairly difficult (for someone like me anyway). You need to know how many pixels are being taken up by that object on the scene, which means you need to measure the screenspace of each face on the object.

I'm not going to go through the math because I don't know it, but it's probably something similar to finding the z distance to the vertexes that make up the face, calculate that distance, scale the measurement to screenspace (this is the difficult part, probably...), compare that distance to the screen's width/height (which is in pixels afaik).

Good luck....

Edit: I'm sorry but I suck at explaining math...

Comment
Add comment · Show 1 · 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 Rabwin · May 09, 2013 at 11:06 AM 0
Share

"Basically" you're reverse engineering how the camera works. If you can find out how that math is done, then you're probably set.

avatar image
0

Answer by robertbu · May 09, 2013 at 11:55 AM

Assuming the plane is axis aligned and parallel to the camera, you can use Camera.WorldToScreenPoint() to translate the size. Note that the build-in plane when it is scaled to (1,1,1), is 10 units on a side.

 var planeScale = 10.0;
 
 function Update () {
 
     if (Input.GetKeyDown(KeyCode.Space)) {
         var v3 = Vector3(planeScale * transform.localScale.x, planeScale * transform.localScale.y, transform.position.z);
         v3 = Camera.main.WorldToScreenPoint(v3);
         var v3Zero = Camera.main.WorldToScreenPoint(Vector3.zero);
         v3 = v3 - v3Zero;
         Debug.Log("Image screen size: " + v3.x  + " x " + v3.y); 
     }
 }

Note this gives you a fractional amount which I think you can use Mathf.RoundToInt() but may have to do a Mathf.CeilToInt() to get the exact size. Note you will get the same value even if the plane is only partially visible.

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 ocimum · Oct 05, 2015 at 02:52 PM

You can access the real planes size by the mesh bounds:

 Mesh planeMesh = _plane.GetComponent<MeshFilter>().mesh;
 Bounds bounds = planeMesh.bounds;

 // size in pixels
 float boundsX = _panel.transform.localScale.x * bounds.size.x;
 float boundsY = _panel.transform.localScale.y * bounds.size.y;
 float boundsZ = _panel.transform.localScale.z * bounds.size.z;

Of course, the panels factor of the panel is set to 10, but in case you would change it, your script would not be correct anymore. This way you can use it on each plane, doesn't matter if the factor has been changed!

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

15 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

Related Questions

How to get expanding object collide when it touches others? 1 Answer

C# How to Drag and Scale with Mouse Window 0 Answers

Particles shape scales issue after upgrading Unity to 4.2.2 0 Answers

Have a question about the scale of environments and assets in them. 1 Answer

Question about creating large scale games in Unity 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