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

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

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

你可能感兴趣的:(UnityProject)