减速

复制代码
using UnityEngine;
using System.Collections;

public class stopSpeed : MonoBehaviour {

    public bool canStop = false;
    public float scrollSpeed = 5.0f;

    // Use this for initialization
    void Start () {

    }
    
    // Update is called once per frame
    void Update () {
        if(canStop == true){
            canStop = false;
            StartCoroutine(StopScrolling(20.0f));
        }
    }

    IEnumerator StopScrolling (float time)
    {
        //Slow down to 0 in time
        var rate = 1.0f / time;
        var t = 0.0f;
        float startValue = scrollSpeed;

        while (t < 1.0f) 
        {
            t += Time.deltaTime * rate;
            scrollSpeed = Mathf.Lerp(startValue, 0, t);

            yield return new WaitForEndOfFrame();
        }
    }
}
复制代码

 

posted @   softimagewht  阅读(231)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示