How do I sync non-player GameObject properties in UNet/Unity5?

前端 未结 4 863
遇见更好的自我
遇见更好的自我 2020-12-09 22:32

I\'m working on and learning some basics of Unity 5, UNET, and networking. I made a simple 3D game where you go around and change the colors of objects. But I want to make i

4条回答
  •  醉梦人生
    2020-12-09 23:03

    For 2018:

    Rather than using "Assign Object Authority",

    I really recommend simply using

    .SpawnWithClientAuthority

    It's really very easy.

    In fact it's this simple!

      [Command]
      void CmdPleaseSpawnSomething() {
     
            GameObject p = Instantiate(some_Prefab);
            NetworkServer.SpawnWithClientAuthority(p, connectionToClient);
        }
    

    {In that code, note that "connectionToClient" is magically available with no effort - it means "the client" who called this command.}

    On the client (the one you want to "own" the thing), just call CmdPleaseSpawnSomething().

    I mean - that's all there is to it, thank goodness.

    There's a long clear explanation here:

    https://forum.unity.com/threads/assign-authority-to-local-client-gameobject.371113/#post-3592541

提交回复
热议问题