• 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 Aldwoni_legacy · May 23, 2011 at 01:27 PM · gameobjectheight

How I know the height of a gameobject?

Is there a way to know the height of an gameobject?

If I create 3 cubes on top of eachother, how do I know the height of each of them?

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
2
Best Answer

Answer by Joshua · May 23, 2011 at 01:35 PM

Well the easiest way is to draw a box around the object which encloses it on the x,y and z axis. If you want to do it that way check out Bounds.size.y

  • Edit:

I see you edited your question to only concern cubes. Since the default height of a cube is 1 unit, the height of three cubes on top of eachother is cube1.transform.localScale.y+cube2.transform.localScale.y+cube3.transform.localScale.y;.

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 Aldwoni_legacy · May 24, 2011 at 08:02 AM 0
Share

the problem is that I don't have one stack of cubes but multiple. How do I know which stack is highest? and most likely cubes will not be the only item. so what if a big cube it part of multiple stacks?

avatar image
2

Answer by demize2010 · May 23, 2011 at 01:29 PM

If your talking about the y axis.

 transform.lossyScale.y

http://unity3d.com/support/documentation/ScriptReference/Transform-lossyScale.html

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 Joshua · May 23, 2011 at 01:37 PM -1
Share

Right but this way you have to multiply the scale by the original height and compensate for any scaling on part of the parent and it's parent, etc.

avatar image FabDynamic Joshua · Mar 07, 2018 at 09:39 PM 0
Share

No the docs say that lossyScale accounts for parent scales for you. Its not perfect though (due to possible skews)

avatar image
1

Answer by CHPedersen · May 24, 2011 at 08:16 AM

Check out http://answers.unity3d.com/questions/120387/measuring-the-length-of-objects.html as well, which deals with the length of an object; a question analog to this one.

In short, if your GameObject has geometry that gets drawn, then it also has a MeshRenderer. If it has a MeshRenderer, then it also has a bounds-property, since MeshRenderer inherits from Renderer. If it has a bounds-property, then you always have access to its bounding box, which gives you the dimensions of the object.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Difference between scale and height in a gameobject with charactercontroller 1 Answer

[UNSOLVED] Get a GameObject width and height in pixels (JS) 3 Answers

Adjust the terrain to a mesh 0 Answers

Instantiated Objects not being set at ground/terrain level?(Solved) 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