0
我已经设法使用这些步骤解决了此问题。下面给出了这些步骤,以便将来的用户不会陷入这个问题:
通过网络身份和网络转换制作一个用于头部的游戏对象(简单的立方体)
通过网络身份和网络转换为一个控制器(简单的立方体)制作一个Gameobject
通过网络身份和网络转换为其他控制器(简单的立方体)制作一个Gameobject
制作上述所有游戏对象的预制件。
将所有三个预制件添加到网络管理器中(已注册的可拥生成预制件列表)
从场景中删除三个预制件
在我的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;
}
}
收藏