1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-21 01:36:05 +08:00
2020-01-17 00:11:15 +09:00

36 lines
930 B
C#

using UnityEngine;
using System.Collections;
using DG.Tweening;
public class InfinitePulseAndSmoothHover : MonoBehaviour
{
Tween pulseTween;
void Start()
{
// Create the pulse tween and pause it
pulseTween = this.transform.DOScale(1.3f, 0.5f)
.SetEase(Ease.InOutQuad)
.SetLoops(-1, LoopType.Yoyo)
.Pause();
}
void OnMouseEnter()
{
// Just play forward
pulseTween.PlayForward();
}
void OnMouseExit()
{
// Find the current elapsed duration without considering loops,
// then goto it and play the tween backwards.
// I'm gonna use ElapsedDirectionalPercentage instead of Elapsed,
// because I want Yoyo loops to be considered correctly inverted as they are
// pulseTween.Goto(pulseTween.ElapsedDirectionalPercentage() * pulseTween.Duration(false));
// pulseTween.PlayBackwards();
// That said, I just added a SmoothRewind method so you can use that :P
pulseTween.SmoothRewind();
}
}