Unity_Bug_记录

版权声明: https://blog.csdn.net/f980511/article/details/82902624

【版本2017.3.0f3(64bit)】 不正常运行

【版本Unity 5.6.1f1(64bit)】正常运行

   【实现策略】

      同一帧内使用<Rigidbody>移动物体前会因为<Transform>的影响无法实现移动

   【实例代码】

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tests : MonoBehaviour {

    Vector3 preUpdate, postUpdate;
	
	// Update is called once per frame
	void Update () {

        preUpdate = transform.position;
        transform.position = transform.position + new Vector3(0.01f, 0, 0);
        postUpdate = transform.position;
        {
            transform.position = preUpdate;
            GetComponent<Rigidbody>().MovePosition(postUpdate);
        }
    }
}

 【原因】

  1.MovePosition()函数并未正常执行--其获取的当前自身位置可能并未经过Transform的更新而更新

 【效果图】

 【版本Unity 5.6.1f1(64bit)】正常运行       

       

【版本2017.3.0f3(64bit)】 不正常运行 

猜你喜欢

转载自blog.csdn.net/f980511/article/details/82902624
今日推荐