Author Topic: adjusting the dimensions of UISlicedSprite in script  (Read 2240 times)

tinyutopia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
adjusting the dimensions of UISlicedSprite in script
« on: September 15, 2012, 03:04:01 PM »
I feel like this should not be too difficult, but I cannot get any results with the solutions proposed in this forum. Currently I have this, which does not appear to scale the sprite at all.

public GameObject Icon;
Icon.transform.localScale += new Vector3(1.5f, .1f, 0);

Is there another way to change the dimensions of a slicedsprite so I can keep changing it throughout my script?

dlewis

  • Guest
Re: adjusting the dimensions of UISlicedSprite in script
« Reply #1 on: September 15, 2012, 08:42:20 PM »
I've never done a += operator on a transform component. Try assigning the local scale to a temp vector3, add to it and then assign it back

  1. public GameObject icon;
  2. Vector3 scale = icon.transform.localScale + new Vector3(1.5f, 0.1f, 0.0f);
  3. icon.transform.localScale = scale;

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: adjusting the dimensions of UISlicedSprite in script
« Reply #2 on: September 16, 2012, 01:23:52 AM »
Sprites are in pixels. If your sprite is 200x100 pixels, adding (1.5, 0.1) to it will simply make it (201.5, 100.1), which is going to be barely visible.