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 velv · May 25, 2012 at 10:01 PM · scaleparentchild

Parenting issue: Building and windows (scaling them as a whole entity)

Another question came about after i solved the main [problem][1] . Now i have to change (by code) the XYZ scale of my building (parent) and the windows i placed upon it (children) must change too according to the new scaling of their parent.

I checked here some parenting forum topics,but did not helped me much, cause the answers were for a specific question on parenting that someone had.

I am aware of the transform.parent.localScale but i do not know how to use it in my case. Here is the code:

 function Start () {
 
 //--Main Building Objects-----------------------------------------------------------
  var oHouse = GameObject.CreatePrimitive(PrimitiveType.Cube);
  var oWindow = GameObject.CreatePrimitive(PrimitiveType.Cube);
  
  //----Start oHouse-------------------------------------------
 //Random ranges between X, Y coordinates
 var RandX = Random.Range(-100,100);
 var RandZ = Random.Range(-100,100);
 
 //Scaling the oHouse object
 oHouse.transform.localScale.x = 7.0;
 oHouse.transform.localScale.y = 12.0;
 oHouse.transform.localScale.z = 7.0;
 
 //Positioning the oHouse object
 oHouse.transform.position = Vector3(RandX,6.35569,RandZ);
 //----End oHouse-------------------------------------------
 //----------------Start oWindow-------------------------------------
 //Scaling the oWindow object
 oWindow.transform.localScale.x =1.1;
 oWindow.transform.localScale.y = 1.116753;
 oWindow.transform.localScale.z = 1.0;
 
 var wind_X = RandX + 2.82102;
 var wind_Y = 11.474193;
 var wind_Z = RandZ + 3.014586;
 
 //Positioning the oWindow object
 oWindow.transform.position = Vector3(wind_X,wind_Y,wind_Z);
 
 oWindow.transform.renderer.material.color = Color.clear; //transparency

 oWindow.transform.parent = oHouse.transform;      //make oWindow object child to oHouse object, parenting
 
 
 var aTopWindows = new Array(); // an Array - a collection- for the top windows
 var i: int;
 var nPosX_TW: float = wind_X - 1.9;
 
 for(i=0; i<=2; i++){
     if(oWindow != null) {//if the object oWindow exists 
         var cloneTopWindows = Instantiate(oWindow, Vector3(nPosX_TW,wind_Y,wind_Z), Quaternion.identity); //make 3 more clones of the oWindow object and place them near to it
         cloneTopWindows.transform.localScale.x =1.1;
         cloneTopWindows.transform.localScale.y = 1.116753;
         cloneTopWindows.transform.localScale.z = 1.0;
         aTopWindows.Add(cloneTopWindows);
         nPosX_TW-=1.9;
         cloneTopWindows.transform.parent = oHouse.transform; //parenting
     } //end if
 } //end for
 //----------------End oWindow-------------------------------------
 } //End  Start()
 

When i changed the scale coordinates of the oHouse object and play the scene, i saw a tiny box in the place of oHouse Building and the windows' scale was remained unchanged. Anyone knows why? Thanks in advance. [1]: http://answers.unity3d.com/questions/256544/placing-parallel-window-objects-into-a-building.html

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
1

Answer by whydoidoit · May 25, 2012 at 10:56 PM

Well you are setting a scale before setting transform.parent - that's one of those weird things that happen with ordering.

Basically when you set transform.parent it will keep the windows the same WORLD scale as they were before they had a parent. (Their localScale will change!) If you want to set them in proportion set their scaling after the transform.parent = statement.

If you add things to a parent, then scale the parent, the children scale automatically (that's why it's localScale).

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 velv · May 26, 2012 at 10:37 AM 0
Share

If i'm following right ur instructions you said to use the transform.parent statement for each (child) object before i set their localScale statement, right? It didn't work. You can test it as well. But thank you helping me out.

avatar image whydoidoit · May 26, 2012 at 06:07 PM 0
Share

Believe me I use that code everywhere, that ordering makes a difference.

You should be able to add normally sized windows to a normal sized house (by setting their transform.parent) then scale the whole unit by scaling the house. If the house is already scaled then you would have to scale the windows as well before you add them, or set their normal scale afterwards.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

How to Prevent Child Deformation on Rotate? 1 Answer

setParent either shrinks my child object or blows it up... What gives? 3 Answers

Make child on the edge of the parent circle while scaling 0 Answers

Make gameobject a child without affecting scale? 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