Unity学习笔记010.平滑移动

	private Vector3 targetPosition = new Vector3(-1.9f, -4, 0);
	private Vector3 originPosition = new Vector3(0, -4, 0);
	private Vector3 currentVelocity = Vector3.zero;
	private bool move;

	private void OnEnable()
    {
        move = false;

        // 由于每一个带有动画的模型都需要各自的光照,故添加此动态调节的光照
        var light = UtilsSearch.FindComponentChild<Light>(GameObject.FindGameObjectWithTag(StaticData.LightSystemTag).transform, StaticData.LightSourceName);
        light.intensity = 0.5f;
    }

	private void LateUpdate()
    {
        if (move)
        {
            transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref currentVelocity, 1);
        }
        if (!move)
        {
            transform.position = Vector3.SmoothDamp(transform.position, originPosition, ref currentVelocity, 1);
        }
    }

	/// <summary>
    /// 动态移动模型
    /// </summary>
    public void MoveStart()
    {
        move = true;        
    }

    /// <summary>
    /// 模型归位
    /// </summary>
    public void MoveEnd()
    {
        move = false;        
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章