mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-20 17:26:03 +08:00
25 lines
794 B
C#
25 lines
794 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using DG.Tweening;
|
|
|
|
public class FollowTargetUntilReached : MonoBehaviour
|
|
{
|
|
public Transform targetToFollow;
|
|
public Transform follower;
|
|
|
|
void Start()
|
|
{
|
|
// Create tween and use OnUpdate to follow that target.
|
|
// In this case, when the target is reached the tween will be
|
|
// automatically killed and the following will stop
|
|
Vector3 prevTargetPos = targetToFollow.position;
|
|
Tweener followTween = follower.DOMove(targetToFollow.position, 4);
|
|
followTween.OnUpdate(()=> {
|
|
if (prevTargetPos != targetToFollow.position) {
|
|
prevTargetPos = targetToFollow.position;
|
|
followTween.ChangeEndValue(targetToFollow.position, 2, true).Restart();
|
|
}
|
|
});
|
|
followTween.OnComplete(()=> Debug.Log("Target reached and tween killed"));
|
|
}
|
|
} |