Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[C#] Scaling a parent, should effect the child object

Discussion in 'Scripting' started by MewEight, Mar 13, 2014.

  1. MewEight

    MewEight

    Joined:
    Feb 28, 2014
    Posts:
    10
    Code (csharp):
    1.  
    2.     void Update ()
    3.     {
    4.         scaleNumber =  Vector3.Distance(transform.position, Camera.main.transform.position) * scaleRatio;
    5.         transform.localScale = new Vector3(scaleNumber, scaleNumber, scaleNumber);
    6.     }
    The code above is attached to the parent of an object. The object holds other child object. By scaling it like this it should be scaling the child objects as well isnt it? In the inspector, i checked that the scale of the child object doesnt change, but the parent object changes. Would like some help on how to get the scaling to affect the child as well.
     
  2. Diviner

    Diviner

    Joined:
    May 8, 2010
    Posts:
    677
    The scale you notice on the inspector is the local scale, which is, the child's scale relative to its parent. Scaled as it is, remove it from its parent and watch its scale instantly changing in the transform values without actually changing the object's size.
     
  3. MewEight

    MewEight

    Joined:
    Feb 28, 2014
    Posts:
    10
    The scale on the child doesnt increase though. And how would i go about to increase the child's scale if i want to?
    I switched the scaling method of the object is because i thought that scaling one parent object will be better than scaling the 4 child objects itself.

    This is how the hierarchy looks like. I would like to scale the child of the letterHolderPrefab acording to the scale of the letterHolderPrefab

    $pic1.png
    $pic2.png
     
    Last edited: Mar 13, 2014
  4. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    What Diviner means is that the object does get bigger, but the scale number doesn't go up in the inspector because it's showing the scale relative to its parent. If the local scale also doubled when you doubled the parent's scale, then it would actually be four times as big.
     
  5. MewEight

    MewEight

    Joined:
    Feb 28, 2014
    Posts:
    10
    Ah thanks! i was too quick to judge and did not really run a full test. Thanks Diviner too~