Pulsing effect on transform
« on: June 24, 2015, 08:31:33 AM »
Hellos,

Just bought DOTweener so I am pretty new with it.

I would like to do pulsing effect to my gameobject when mouse over.

Like it to scale up to 3x from it original size then back to normal size... and continue this as long I got mouse is over.

How i should do it?

something like this:

void OnMouseEnter()   
{
   transform.DOScale(3, 1);
   // What I should do here?
}

void OnMouseExit()
{
 // Should I do something here?
}

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Pulsing effect on transform
« Reply #1 on: June 24, 2015, 02:50:31 PM »
Hello, and thanks for buying!

To do that you have two options: simply Rewind the tween when the mouse exits, which will immediately jump to the beginning of the tween, or SmoothRewind it, which will play the tween backwards (ignoring any loop count) until the target reaches its initial state.

Code: [Select]
Tween myTween;

void Start()
{
   // Create and store the tween so you can reuse it,
   // also add infinite loops (so it pulses until it's manually stopped/rewinded)
   // and set its autoKill status to FALSE, so it won't be automatically
   // destroyed when completed.
   // Finally, set its state to paused, so it will be played only on mouse enter
   myTween = transform.DOScale(3, 1).SetLoops(-1, LoopType.Yoyo).SetAutoKill(false).Pause();
}

void OnMouseEnter()
{
   // Play the tween
   myTween.Play();
}

void OnMouseExit()
{
   // CHOOSE:
   // either rewind immediately
   myTween.Rewind();
   // or rewind with animation
   myTween.SmoothRewind();
}

Re: Pulsing effect on transform
« Reply #2 on: June 24, 2015, 08:45:35 PM »
Thank.. Working great , but got still one problem:

I flip objects to get sprites facing left or right with:

Multiplying localSacle with -1, this cause tween spin object.

How I can fix this? I should not want to add flipping as animation.

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: Pulsing effect on transform
« Reply #3 on: June 25, 2015, 07:02:31 PM »
You can't flip the objects (by changing their scale to negative) while the tween is playing, because the tween will overwrite the scale you set. The solution would be to place your object inside a parent, tween the child, and change the parent's scale to negative when you want to flip it.