Search Unity

changing transform.scale

Discussion in 'Scripting' started by Thordis, Nov 3, 2006.

  1. Thordis

    Thordis

    Joined:
    Mar 1, 2006
    Posts:
    18
    Hey,
    I'm currently working on a little strategy game, so far so good, you can select and move the tanks, particle animations for shooting and smoke etc.

    One minor confusing hiccup, however. The units above their heads have little billboards that should indicate their health. I'd like to scale this based on the units health.

    Here is the line to do so:

    transform.Find("bb_Health").transform.Scale.x = 3*((100-Health)/100);

    However, Unity complains that "Scale" is not a member of Transform. I get the same error for "scale"

    How do I alter the scale of the object realtime?

    Cheers,
    Thordis
     
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
  3. Thordis

    Thordis

    Joined:
    Mar 1, 2006
    Posts:
    18
    Ah thanks, I couldn't get it to work at first, and tried about a hundred things, but in the end the solution was to break it up into atleast two lines:

    var bbHealth : Transform = transform.Find("bb_Health");
    bbHealth.localScale.x = 3.0*((Health)/100.0);

    Now it works like a dream, thank you.

    Cheers