Demigiant Forum

Unity Assets => DOTween & DOTween Pro => Topic started by: Brick on April 11, 2016, 08:30:51 PM

Title: Start a tween on another object from a trigger.
Post by: Brick on April 11, 2016, 08:30:51 PM
Hi i have a chest and i want to activate a tween on a key which is under the chest. so when the plkayer enters the chest colider i want to play the move tween on the key.

Not sure how to go about this thanks

Daniel
Title: Re: Start a tween on another object from a trigger.
Post by: Daniele on April 11, 2016, 08:34:53 PM
Hi,

If you're using DOTween Pro, just give you tween a special ID (like "key"), then call

Code: [Select]
DOTween.Play("key");
If instead you're doing it all by code, as long as you grab a reference to your key transform (or whatever you want to animate) you can tween it from anywhere.

Cheers,
Daniele
Title: Re: Start a tween on another object from a trigger.
Post by: Brick on April 11, 2016, 08:45:11 PM
This is super cool. Thanks Daniele
Title: Re: Start a tween on another object from a trigger.
Post by: Daniele on April 11, 2016, 08:48:07 PM
P.S. If using DOTween Pro, remember to set the tween as paused (and even disable autoKill if you plan to call it multiple time, in which case you'll need DOTween.Restart("key") instead of just Play) :)
Title: Re: Start a tween on another object from a trigger.
Post by: Brick on April 11, 2016, 09:42:22 PM
Awesome thanks for the tip,

Got one more Q: Fade doesnt seem to be fading .. I have attached a screen shot of the code and the settings for reference.. sure its me being stoopid but a pointer int he right direction would be great..

Thanks
Title: Re: Start a tween on another object from a trigger.
Post by: Daniele on April 11, 2016, 10:11:50 PM
When used with a material, you need a material that supports transparency, otherwise even if DOTween is actually changing its alpha, nothing will happen. As a rule of thumb, if you can change a material color's transparency yourself and it will work, then the fade will work too.
Title: Re: Start a tween on another object from a trigger.
Post by: Brick on April 11, 2016, 11:04:34 PM
Aah ok

Thanks
Title: Re: Start a tween on another object from a trigger.
Post by: raiden on April 14, 2016, 12:45:29 AM
I am having a similar issue, where as I want my menu buttons to animate in from different directions, then when I press the button, for example the credits UI, I want to animate back out the menu buttons, and animate in the credits UI. I am not getting a PlayBackwards call for the menu buttons to work, I'm not sure if it is because I have PlayForward and PlayBackwards setup on my buttons PointerEnter and PointerExit events.

What does PlayRestart do? Is it similar to PlayBackwards? Also, what is the correct setup for an animation you want to reuse, like my menu buttons, I want to be able to animate them in and out of the menu scene.

Thanks

[EDIT] So far I have been able to work this out :) Mainly my issues were because of incorrect references.
Title: Re: Start a tween on another object from a trigger.
Post by: Daniele on April 15, 2016, 12:37:33 PM
Hi! ANd glad you solved it in the meantime :)

DORestart does a rewind and then a playForward, so it's very different from playBackwards. And to reuse animations you should always untoggle the AutoKill behaviour, otherwise the tween will be destroyed as soon as it ends.

Cheers,
Daniele
Title: Re: Start a tween on another object from a trigger.
Post by: arico on April 22, 2016, 07:50:50 PM
Hello,

Please, how do I assign an id to a tween?.  Is it in the editor or by code?.

Thx
Title: Re: Start a tween on another object from a trigger.
Post by: Daniele on April 22, 2016, 07:54:25 PM
Hi!

In DOTween Pro's editor there is a field called "ID", and that's where you assign it. When you create a tween via code instead you can chain a SetId (http://dotween.demigiant.com/documentation.php?api=SetId).
Title: Re: Start a tween on another object from a trigger.
Post by: arico on April 22, 2016, 09:00:45 PM
Hello Demigian,

In my scene I did this: placed an object (cube), added to it a script "Do Tween Path" and I wanted this path to be executed when the first person controller arrives to a collider.  So I added an script to the object with the collider with the instruction: Dotween.Play("cube"), but that doesn't work, the tween doesn´t execute.  Is it there a way to execute this path in such so simple way?.  Do I need to add any instruction to find the id of the path or the id of the gameobject, or I cannot execute this path when something enters a collider (like if this -enter the collider- would work like a switch to execute/stop this object moving through the path?


Thank you very much!  :)
Title: Re: Start a tween on another object from a trigger.
Post by: Daniele on April 22, 2016, 10:57:07 PM
Hello,

And oops, my bad. I assumed you were talking about DOTweenAnimations, not DOTweenPaths. For some mysterious reason, I didn't add an ID field to DOTweenPaths, and no one requested it before. That said, here you go, I just updated DOTween Pro (http://forum.demigiant.com/index.php?topic=1083.0) so there's the ID field on paths too. Just reimport the package and re-run the Setup as usual :)

P.S. Once you give your path an ID (for example "MyID") you can call DOTween.Play("MyID").

Cheers,
Daniele
Title: Re: Start a tween on another object from a trigger.
Post by: arico on April 23, 2016, 12:39:17 PM
Amazing!  Thank you!  :)
Title: Re: Start a tween on another object from a trigger.
Post by: brianwanamaker on May 31, 2016, 09:15:25 AM
Hi! ANd glad you solved it in the meantime :)

DORestart does a rewind and then a playForward, so it's very different from playBackwards. And to reuse animations you should always untoggle the AutoKill behaviour, otherwise the tween will be destroyed as soon as it ends.

Cheers,
Daniele

Hi! I'm using DOTween Components (I'm just barely beginning with programming).

I have a similar problem initiating repeated play of UI elements that are triggered by Button presses.

Separate buttons for DOPlay and DOPlayBackwards. Both work as expected with the first button press. I can DOPlay to its desired display position, and then DOPlayBackwards to have it move back to its initial, hidden position.

However, after it returns to its initial position via DOPlayBackwards, Pressing the button with DOPlay will not play the animation again.

It /will/ work repeatedly if I use DOPlayForwards, though. Why is that?
Title: Re: Start a tween on another object from a trigger.
Post by: Daniele on May 31, 2016, 11:05:10 AM
Hi!

DOPlay just plays the tween regardless of the current direction. So, if you last played it backwards, it will continue playing it backwards (and nothing will happen if it's already rewinded). DOPlayForward instead sets the direction and then plays.
Title: Re: Start a tween on another object from a trigger.
Post by: brianwanamaker on June 01, 2016, 03:40:24 AM
Oh, that makes perfect sense! Thanks for the explanation.