Unity学习笔记010.平滑移动

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_33643757/article/details/86220202
	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;        
    }

猜你喜欢

转载自blog.csdn.net/baidu_33643757/article/details/86220202