鸟语天空
TweenPingPong
post by:追风剑情 2017-8-24 19:43
/// <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);
    }
}
评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容