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

 

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2021-10-17
  • 2021-12-02
  • 2021-05-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-02
  • 2022-02-02
  • 2021-12-26
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案