Author Topic: implement shake animation on anchored button  (Read 2908 times)

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
implement shake animation on anchored button
« on: September 04, 2014, 07:46:04 AM »
I implemented my gui with different buttons that are all anchored and stretched in order to adapt to multiple screens resolutions. I want to add a shake animation to some of them to be triggered via a script but I was wondering what's the best way to approach this because the anchor script will always keep my button element at the same position. Is it possible to use the NGUI Tween class without disabling the anchor component? Thanks.

ionutztamas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 6
    • View Profile
Re: implement shake animation on anchored button
« Reply #1 on: September 04, 2014, 09:26:39 AM »
Yes, it is possible to add NGUI Tweens to the object that has anchors. I'm doing exactly that with some user interface components that are hidden at first (they are just outside of the screen) but then show up when you press a button. Those are anchored and everything works. If you look in the inspector during the tween, the anchor values get updated as well.

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: implement shake animation on anchored button
« Reply #2 on: September 08, 2014, 02:17:05 AM »
Hi there, thanks for your reply. How to you do it exactly? I tried to attach a tween scale component to one of my buttons, then I get the component with myButton.gameObject.GetComponent<TweenScale>(); and I call Play() but the animation doesn't play. It seems though that the collider box does animate, but not the sprite of the button.

Thanks

Nubeh

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: implement shake animation on anchored button
« Reply #3 on: September 08, 2014, 02:17:50 AM »
as a note: I'm using the legacy Anchor and Stretch components...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: implement shake animation on anchored button
« Reply #4 on: September 08, 2014, 08:49:44 PM »
You need to use built-in anchoring provided by the layout system. Legacy UIAnchor and UIStretch components predate the layout system, so they don't work with it.

You can still accomplish what you want even with legacy anchors, but you need to structure your hierarchy like so:

UIAnchor
- Shake Effect
-- Your UI elements