Unity-Technologies/com.unity.multiplayer.samples.coop

How is PLayerServerCharacter script is working

Fedi15 opened this issue · 3 comments

Hello , i want some help to understand playerServerCharacter script how the list is full of the all player in scene all i see it's on network spawn addiing current player to that list isn't should the list have only one player how the imp can detect all player from it because i wanna use the same way to make npc detect npc summonde from player and thanks

PlayerServerCharacter executes server side. There's one for each new player. Since the server has the authority over all players, each time a new player is created, it'll be spawned server side (when a new player joins).

Once a new PlayerServerCharacter is created, it will add itself to the static list.

You can find where players are spawned in ServerBossRoomState's SpawnPlayer on our develop branch.

I suggest you add breakpoints and debug logs in PlayerServerCharacter, you'll see what happens when you join a new client.

Hope this helps.

Okay let's say i wanna use same methode for the imps not player should i make if change instead of if server to client when adding new imp because i tried if server but it didn't work

Not sure I follow.
To spawn a network object, just instantiate + spawn it.
To keep track of them, you can use a static list and register them to it in their respective OnNetworkSpawn.