减速

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();

        }

    }

}

 

你可能感兴趣的:(减速)