就是tween在播放动画的时候具有实时效果,完成的时候可以保持当时的位置,修改动画的起点和终点实现相对距离无限移动的效果,而不是一直的重复播放一个动画。
先看结果。对于这种实时效果,动态的改变起点和终点变化最好。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class test1 : MonoBehaviour
{
// Start is called before the first frame update
Tweener twer;
bool begin;
void Start()
{
twer = transform.DOLocalMove(new Vector3(0, 0, 0), .2f)
.SetAutoKill(false)
.SetRelative()
.Pause()
;
}
public void SetPos()
{
//重新设置起点和终点
twer.ChangeValues(transform.position, transform.position + new Vector3(0, 2, 0), .2f);
}
public void SetPos2()
{
//重新设置起点和终点
twer.ChangeValues(transform.position, transform.position - new Vector3(0, 2, 0), .2f);
}
public void PlayForward()
{
begin = true;
SetPos();
twer.Play();
}
public void PlayBack()
{
begin = false;
SetPos2();
twer.Play();
}
}
哇,我研究了好久的,您觉得有点用的,跪求点个关注,哈哈。