简体   繁体   中英

command for object without authority mirror

I having problems with unity mirror. When respawn IEnumerator is called, the player respawn but it disconnect from the server, he cant move (only locally) and he cant do commands. this is the respawn code:

    [Server]
IEnumerator Respawn(GameObject go){
    print("Player ded");
    NetworkServer.UnSpawn(go);
    Transform newPos = NetworkManager.singleton.GetStartPosition();
    go.transform.position = newPos.position;
    go.transform.rotation = newPos.rotation;
    yield return new WaitForSeconds(1f);
    NetworkServer.Spawn(go);
}

Any solutions to that problem please?

I would need the whole script to make sure I am right, but I am pretty sure, that the problem is that you call [Server] via a client (which isn't allowed).

[Server] is used to make sure that only the server can call the function. Not a client, that would explain why the player is disconnected, when the function is called.

It would probably work if you change [Server] to [Command(requiresAuthority = false)]. Link to the [Command] documentation: Mirror documentation If not please send the whole script.

With regards,

Aaron

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM