TweenPingPong

作者:追风剑情 发布于:2017-8-24 19:43 分类:Unity3d

/// <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);
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号