1

我的行为很奇怪,如果我的播放器实例化为主机(服务器 + 播放器),那么我的命令函数运行完美并且某些对象变为实例化,但是如果我加入主机,那么我的命令不会在我的本地播放器上执行,而是在所有播放器上运行其他客户。

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);     
}
4

0 回答 0