我的行为非常奇怪,如果我的播放器实例化为主机(Server + Player),那么我的命令功能运行完美,某些对象变为实例化但如果我加入主机,那么我的命令不会在我的本地播放器上执行但是在所有其他客户端运行。
void Start()
{
if (isLocalPlayer)
{
Debug.Log("It is VR Player spawn-Start");
SetVRLocalPlayerSetting();
//InstantiateMimicVRHeadAndController();
CmdInstantiateMimicVRHeadAndController();
}
else
{
Debug.Log("It is not vr Player its not isLocalPlayer");
DisableSelectedMonobevaiourScripts();
}
}
[Command]//This function have a problem
public void CmdInstantiateMimicVRHeadAndController() {
Debug.Log("instantiateing the controller and head object");
vrHeadCopyObj = (GameObject) Instantiate(vrHeadObjPrefab);
vrRightCtrlCopyObj = (GameObject) Instantiate(vrRightCtrlPrefab);
vrLeftCtrlCopyObj = (GameObject) Instantiate(vrLeftCtrlPrefab);
// spawn the bullet on the clients
NetworkServer.Spawn(vrHeadCopyObj);
NetworkServer.Spawn(vrRightCtrlCopyObj);
NetworkServer.Spawn(vrLeftCtrlCopyObj);
}