按下按键时 Unity 重置 Oculus 位置

我正在尝试创建一个脚本,每当出于校准原因按下按键时,该脚本都会重置(到特定位置)HMD 和控制器位置。我对 Unity 很陌生,所以我所能弄清楚的就是如何获取关键输入。


public class resetPosition : MonoBehaviour

{

    // Start is called before the first frame update

    void Start()

    {


    }


    // Update is called once per frame

    void Update()

    {

        if (Input.GetKeyDown(KeyCode.Space))

            Debug.Log("pressed");

    }

}


HUH函数
浏览 126回答 1
1回答

守着一只汪

您不应该直接更改 VRCamera 的位置。而是将父级添加GameObject到相机并通过例如更改该父级的位置(假设您的脚本已附加到相机)public class ResetPosition : MonoBehaviour{    public Vector3 resetPosition;    private void Awake()    {        // create a new object and make it parent of this object        var parent = new GameObject("CameraParent").transform;        transform.SetParent(parent);    }    // You should use LateUpdate    // because afaik the oculus position is updated in the normal    // Update so you are sure it is already done for this frame    private void LateUpdate()    {        if (Input.GetKeyDown(KeyCode.Space))        {            Debug.Log("pressed");            // reset parent objects position            transform.parent.position = resetPosition - transform.position;        }    }}
打开App,查看更多内容
随时随地看视频慕课网APP