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 /
avatar image
2
Question by geronika2004 · Jul 04, 2011 at 09:26 AM · scaleboundslength

Scale object to certain length

How make object scale to match exact length of its bounds property ?

For example, I need myobject.GetComponent().bounds.size.z to make equal of 5.0f, how can I reach it?

Thank you in advance.

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
7

Answer by Paulius-Liekis · Jul 04, 2011 at 10:15 AM

Something like this could work:

 float targetSize = 5;
 float currentSize = myobject.GetComponent().bounds.size.z; // I'm not sure if this compiles (I guess you need to specify the component type)
 
 Vector3 scale = myobject.trasform.localScale;
 
 scale.z = targetSize * scale.z / currentSize;
 
 myobject.trasform.localScale = scale;
Comment
Add comment · Show 4 · 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 Thom Denick · Aug 15, 2013 at 07:14 PM 0
Share

Genius! Thank you been racking my brain with this.

avatar image Thom Denick · Aug 15, 2013 at 07:19 PM 1
Share

Here's how you would scale an object's height in worldspace to take up 80% of your camera:

             float targetSize = Vector3.Distance(comicCamera.ViewportToWorldPoint(new Vector3(0f, 0.1f, 0f)), comicCamera.ViewportToWorldPoint(new Vector3(0f, 0.9f, 0f)));
             float currentSize = planePrefab.renderer.bounds.size.y;
             Vector3 newScale = planePrefab.transform.localScale;
             newScale.y = targetSize * newScale.y / currentSize;
             planePrefab.transform.localScale = newScale;
avatar image VSZM · Oct 19, 2014 at 02:48 PM 0
Share

What if the object you want to scale is a child object?

avatar image Thom Denick · Oct 19, 2014 at 09:29 PM 0
Share

That becomes tricker. Probably the easiest thing to do is to unparent before you transform. childObject.transform.parent = null;

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to scale object to fit inside a room 1 Answer

True scale of a visible GameObject with many childs 1 Answer

How should one resize a gameobject? 1 Answer

EteeskiTutorials' bullets (raycast bullets with gravity) 1 Answer

Positioning a scalable textures 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