com.unity.multiplayer.samples.coop icon indicating copy to clipboard operation
com.unity.multiplayer.samples.coop copied to clipboard

How is PLayerServerCharacter script is working

Open Fedi15 opened this issue 3 years ago • 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

Fedi15 avatar Sep 13 '22 22:09 Fedi15

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.

SamuelBellomo avatar Sep 15 '22 14:09 SamuelBellomo

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

Fedi15 avatar Sep 16 '22 00:09 Fedi15

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.

SamuelBellomo avatar Sep 20 '22 21:09 SamuelBellomo