Demigiant Forum

Unity Assets => DOTween & DOTween Pro => Topic started by: JosYule on July 04, 2015, 04:02:00 PM

Title: Multiple MOVE DotweenAnimation Components on a single GameObject
Post by: JosYule on July 04, 2015, 04:02:00 PM
Hello!

I just purchased DotweenPro and am trying to do the following.

I have a UnityEngine.UI.Panel on which i've added 2 DotweenAnimation components. One to move the Panel off-screen, the other to move it on-screen. I then have a second component, on a different GameObject, with 2 DotweenAnimation fields. I put each of the Move animations into those fields, which i then call ".DOPlay()" on.

I can get the first one to work, but the second never seems to actually do anything. Am I using the wrong method to start the animations? Any suggestions?

Thanks!
Jos
Title: Re: Multiple MOVE DotweenAnimation Components on a single GameObject
Post by: Daniele on July 04, 2015, 04:09:07 PM
Hello (and thanks for buying!),

Sadly Unity doesn't allow to specify which DOTweenAnimation you're dragging on a Component's variable, so when you drag those 2 animations there, it will actually assign them as the same one.

That said, in your case there's a much better way to do what you mean to. Create only one DOMove animation, which will move the panel on-screen. Deselect autoPlay (so you can control it via your other gameObject) and autoKill (so it can be re-used after it's complete). Then when you want to show the panel, call DOPlayForward(), and when you want to hide it DOPlayBackwards().

Hope this was what you were looking for :)

Cheers,
Daniele
Title: Re: Multiple MOVE DotweenAnimation Components on a single GameObject
Post by: JosYule on July 05, 2015, 02:20:14 PM
Ok, good to know about PlayForward and DOPlayBackwards. However, this is only appropriate if i want the same animation, in reverse, to be the "off" animation. Which we don't always want. An easy example would be a Panel which moves on-screen from the right to the centre. Then moving from the centre to the right till it is off screen.

Thanks
Jos
Title: Re: Multiple MOVE DotweenAnimation Components on a single GameObject
Post by: Daniele on July 05, 2015, 06:51:25 PM
I understand. Then you can either use code or IDs.

With code, you'll need to get all the tweens on the gameObject (with myDOTweenAnimation.GetTweens()): they will be returned in order from top to bottom. With those, you can control which one to play (remember that you can't run two tweens on the same property at the same time, because they will "fight" each other).

Otherwise, you can simply add an ID to each DOTweenAnimation, and use DOPlayById or DORestartById.