Hello Guest

Author Topic: SlicedSprite and UIScaleButton -- won't scale from center anchor point?  (Read 5226 times)

lazypeon

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Just curious if there is an easy way to fix this issue.  Applying a UIScaleButton to a sprite and clicking it in the Game View properly scales the button as you'd expect (from the center, assuming your anchor point for the sprite is set up for the center).

When applying a UIScaleButton to a SlicedSprite, the anchor appears to always be in the lower left, not in middle.

Is it possible to easily correct this?  I've seen similar questions asked, and it was suggested that the user create a parent GameObject and scale that.  I can definitely do that, but was wondering if there was a 'simpler' solution and/or if this behavior is intentional.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
What is the anchor point set on the sliced sprite?
The sliced sprite anchor mode overrides the sprite collection setting.

It will always scale from the origin of the mesh, wherever that may be.
In the unity editor, switch tool mode to "Pivot" and space to "Local" to see where the origin really is. You've likely got it set to center, and its always showing the widget at the center.

lazypeon

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Doh!  Completely missed the anchor point attribute on the Sliced Sprite; I assumed it would take the anchor point of the sprite collection.  Works as expected now.

Many thanks for the quick response, I appreciate it!

wtg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
I'm trying to see if I can use a Sliced Sprite as a button with up an down states. I tried creating a normal sliced sprite and then applied the tk2DButton script but the states become frozen and the button is no longer clickable. I searched the forum and found this thread but I'm unable to setup it properly to see if this is what I'm looking for. Do you have an example of how to set it up right? I basically need to be able to create Sliced Sprites as buttons.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Should work fine. Isn't this just failing because your collider is too large? Try making the boxcollider depth a lot less. Like 0.0001 and see what happens.

wtg

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Hmm, maybe I did it wrong the first time. I just did it again and it works. Thanks.