Hello Guest

Author Topic: Clipped Sprite setting new width doesn't work for me  (Read 3709 times)

Xaron

  • Newbie
  • *
  • Posts: 3
    • View Profile
Clipped Sprite setting new width doesn't work for me
« on: August 23, 2016, 07:17:42 pm »
Hey there,

using Unity 5.4 I try to do some kind of a progress bar and use a clipped sprite for it. Setting it in the editor works perfectly, but not via code:

Start method:
Code: [Select]
_sprite = GetComponent<tk2dClippedSprite>();

Update method:
Code: [Select]
_sprite.SetSprite( "repairing-bar" );
_sprite.clipTopRight.Set( 0.5f, 1.0f );
Debug.Log( _sprite._clipTopRight.x );

_sprite.ClipRect.Set( 0.0f, 0.0f, 0.5f, 1.0f ); doesn't work either...

The editor and debug log both show still 1.0 for the x value (width here) which should be 0.5. I tried ForceBuild() as well but no change. Obviously I'm doing something wrong here?

Thanks!

edit: Well ya got it. My fault. Doing:
Code: [Select]
_sprite.clipTopRight = new Vector2( 0.5f, 1.0f );

is obviously the right thing to do here!
« Last Edit: August 23, 2016, 07:47:53 pm by Xaron »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Clipped Sprite setting new width doesn't work for me
« Reply #1 on: August 24, 2016, 11:04:54 am »
_sprite.clipTopRight is a property returning a struct, which means that calling Set on it will have no effect as you have found.
You will need to assign a new Vector2 to it.