/// <summary>
/// 往复运动
/// </summary>
public class TweenPingPong : MonoBehaviour
{
public Vector3 from = Vector3.zero;
public Vector3 to = Vector3.zero;
public float strength = 2f;
public bool worldSpace = false;
private Transform cacheTrans;
void Awake()
{
cacheTrans = transform;
}
void Update()
{
float distance = Mathf.PingPong(Time.time * strength, 1);
if (worldSpace)
cacheTrans.position = Vector3.Lerp(from, to, distance);
else
cacheTrans.localPosition = Vector3.Lerp(from, to, distance);
}
}