简体   繁体   English

Unity 2019.2.4f1中OVRPlayerController之间的切换

[英]Switching Between OVRPlayerControllers in Unity 2019.2.4f1

Versions: Unity v2019.2.4f1, Oculus Utilities v1.41.0, OVRPlugin v1.41.0, SDK v1.42.0版本:Unity v2019.2.4f1、Oculus Utilities v1.41.0、OVRPlugin v1.41.0、SDK v1.42.0

I am in the process of creating an Oculus Rift game where the player can use buttons to toggle between walking around on the ground and looking around in a bird's eye view of the environment.我正在创建一个 Oculus Rift 游戏,玩家可以使用按钮在地面上四处走动和鸟瞰环境之间切换。 To accomplish this, I am using the following script to toggle between two different OVRPlayerControllers, one positioned on the ground and one positioned in the air looking down:为此,我使用以下脚本在两个不同的 OVRPlayerControllers 之间切换,一个位于地面上,一个位于空中向下看:

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

public class CameraSwitcher : MonoBehaviour

{
    public GameObject firstPersonCameraPrefab;
    public GameObject overheadCameraPrefab;

    void Update()
    {

        bool isDownOne = false;
        bool isDownThree = false;

        isDownOne = OVRInput.GetDown(OVRInput.Button.One);
        isDownThree = OVRInput.GetDown(OVRInput.Button.Three);


        if (isDownOne || isDownThree)
        {
            switchCam();
        }

    }

    public void switchCam()
    {

        overheadCameraPrefab.SetActive(!overheadCameraPrefab.activeInHierarchy);
        firstPersonCameraPrefab.SetActive(!firstPersonCameraPrefab.activeInHierarchy);

    }
}

At the start of the game, the first person player is active, and the overhead player is not active.在游戏开始时,第一人称玩家处于活跃状态,而头顶玩家处于非活跃状态。 When I use this script, the headset toggles between looking through the two cameras.当我使用这个脚本时,耳机会在两个摄像头之间切换。 However, the connection between the game and the movement controls on the controllers gets severed after the first switch.但是,游戏和控制器上的移动控件之间的连接在第一次切换后被切断。 When I toggle back down to the ground, I can no longer use my controllers to move my player around.当我切换回地面时,我无法再使用控制器来移动我的玩家。

How can I switch between players and keep the movement controls in tact?我如何在玩家之间切换并保持移动控制完好?

This is because you have more than 1 OVRManager in your scene, the prefab OVRCameraRig has 1 attached, so if you have more than one of this prefabs, like 2 players, Oculus won't work correctly.这是因为您的场景中有超过 1 个 OVRManager,预制件 OVRCameraRig 已附加 1 个,因此如果您有多个此类预制件,例如 2 个播放器,Oculus 将无法正常工作。

Put the component in an empty prefab that never turns off, and set switch between your player controllers freely.将组件放在一个永远不会关闭的空预制件中,并在您的播放器控制器之间自由设置切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM