mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-20 09:16:02 +08:00
30 lines
574 B
C#
30 lines
574 B
C#
using DG.Tweening;
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class ElasticDragAndRelease : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
Vector3 orPos;
|
|
|
|
void Start()
|
|
{
|
|
orPos = target.position;
|
|
}
|
|
|
|
public void OnClick()
|
|
{
|
|
StartCoroutine(TweenCoroutine());
|
|
}
|
|
|
|
IEnumerator TweenCoroutine()
|
|
{
|
|
float range = 2;
|
|
Vector3 rnd = new Vector3(Random.Range(-range, range), Random.Range(-range, range), target.position.z);
|
|
target.position = orPos + rnd;
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
target.DOMove(orPos, 0.6f).SetEase(Ease.OutElastic, 4, 0);
|
|
}
|
|
} |