Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Nubeh on September 04, 2014, 07:46:04 AM

Title: implement shake animation on anchored button
Post by: Nubeh 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.
Title: Re: implement shake animation on anchored button
Post by: ionutztamas 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.
Title: Re: implement shake animation on anchored button
Post by: Nubeh 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
Title: Re: implement shake animation on anchored button
Post by: Nubeh on September 08, 2014, 02:17:50 AM
as a note: I'm using the legacy Anchor and Stretch components...
Title: Re: implement shake animation on anchored button
Post by: ArenMook 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