我正在开发一个多人游戏,普通角色控制器用户和VR用户可以参与其中.因此,通过用户可以加入的游戏有两种模式,Normal和VR Mode.
@L_403_0@但问题是普通播放器(字符控制器)无法查看VR控制器(HTC vive控制器),因为这些对象在字符控制器一侧关闭.那么我如何在正常玩家端显示VR控制器正在做什么.
(我尝试过的)我制作了一个物体,试图模仿它相对于VR控制器的位置和旋转,但它不起作用,因为模仿源(VR控制器)关闭(在正常的玩家端,但在VR模式下工作)和他们的位置没有改变.如何向其他用户显示vr控制器
解决方法
经过三天的努力,我努力使用这些步骤来解决这个问题.下面给出了这些步骤,以便将来的用户不会遇到这个问题,因为没有其他全面的指南可用:
>使用Network Identity和network transform为头部(简单立方体)制作一个Gameobject
>使用网络身份和网络转换为(右)控制器(简单立方体)创建一个Gameobject
>使用网络身份和网络转换为(左)其他控制器(简单立方体)创建一个Gameobject
>预制所有上述游戏对象.
>将所有三个预制件添加到Network Manager(已注册的Spawnable预制件列表)
>从场景中删除三个预制件
>在我的vr播放器中添加以下脚本(请参阅注释以获取详细信息)并分配相应的预制件和游戏对象
public class VRPlayerCtrl : NetworkTransform { //source gameobjects head,left and right controller object of htc vive prefab public GameObject rightContSource; public GameObject leftContSource; public GameObject headObjSource; //prefabs to assign head,left controller,and right controller public GameObject vrHeadObjPrefab; public GameObject vrLeftCtrlPrefab; public GameObject vrRightCtrlPrefab; GameObject vrHeadObj; GameObject vrLeftCtrl; GameObject vrRightCtrl; void Start() { Debug.Log("Start of the vr player"); if (isLocalPlayer) { //instantiate prefabs CmdInstantiteHeadAndController(); //disabled conroller meshes at VR player side so it cannont be view by him vrLeftCtrl.GetComponent<MeshRenderer>().enabled = false; vrRightCtrl.GetComponent<MeshRenderer>().enabled = false; } } //Instantiate on start head and vr controller object so that it can be view by normal players void CmdInstantiteHeadAndController() { Debug.Log("instantiateing the controller and head object"); vrHeadObj = (GameObject)Instantiate(vrHeadObjPrefab); vrLeftCtrl = (GameObject)Instantiate(vrLeftCtrlPrefab); vrRightCtrl = (GameObject)Instantiate(vrRightCtrlPrefab); // spawn the bullet on the clients NetworkServer.Spawn(vrHeadObj); NetworkServer.Spawn(vrLeftCtrl); NetworkServer.Spawn(vrRightCtrl); } void Update() { if (!isLocalPlayer) { return; } //sync pos on network CmdControllerPositionSync(); } //sync position on VR controller objects so that VR player movemnts/action can be viewd by normal user [Command] public void CmdControllerPositionSync() { vrHeadObj.transform.localRotation = headObjSource.transform.localRotation; vrHeadObj.transform.position = headObjSource.transform.position; vrLeftCtrl.transform.localRotation = leftContSource.transform.localRotation; vrRightCtrl.transform.localRotation = rightContSource.transform.localRotation; vrLeftCtrl.transform.localPosition = leftContSource.transform.position; vrRightCtrl.transform.localPosition = rightContSource.transform.position; } }
恭喜你做到了!