就是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();
}
}
哇,我研究了好久的,您覺得有點用的,跪求點個關注,哈哈。