unity 更漂亮的位移

更漂亮的位移指的是先慢再快再慢的这种位移,更像现实中的位移。也叫平滑阻尼。


这里有两种实现方式:

1.通过计算值:调的函数是Mathf.SmoothStep

例:

    float t = 0;
	// Update is called once per frame
    void Update()
    {
        if(sprite.fillAmount != 1 && transform.gameObject.activeSelf)
        {
            t += Time.deltaTime/5;
            if (m_startAction)
            {
                sprite.fillAmount = Mathf.SmoothStep(sprite.fillAmount, 1, t);
            }
            else
            {
                sprite.fillAmount = 1;
            }
        }


    }

    public void PerformAction()
    {
        m_startAction = true;
    }

2.通过向量Vector3:调的函数是Vector3.SmoothDamp

例:

        if (_buttonUp)
        {
            AddingFriendButton.transform.localPosition = Vector3.SmoothDamp(AddingFriendButton.transform.localPosition, _tabOriginalPosition, ref _velocity, 0.2f);
            if (Vector3.Distance(AddingFriendButton.transform.localPosition, _tabOriginalPosition) < 0.01)
                _buttonUp = false;
        }



你可能感兴趣的:(游戏,unity,界面,U3D)