当本地播放器不是主机

时间:2017-02-02 05:12:36

标签: c# unity3d unity5 unity-networking unet

我的行为非常奇怪,如果我的播放器实例化为主机(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);     
}

0 个答案:

没有答案