mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Updated ChildObjects doc
This commit is contained in:
parent
9e1cb624ac
commit
af28ab425a
@ -2,17 +2,21 @@
|
||||
|
||||
Frequently the question comes up about how to handle objects that are attached as children of the player prefab that all clients need to know about and synchronize, such as which weapon is equipped, picking up networked scene objects, and players dropping objects into the scene.
|
||||
|
||||
Mirror cannot support multiple Network Identity components within an object hierarchy. Since the Player object must have a Network Identity, none of its descendant objects can have one.
|
||||
> Mirror cannot support multiple Network Identity components within an object hierarchy. Since the Player object must have a Network Identity, none of its descendant objects can have one.
|
||||
|
||||
## Simple Case
|
||||
|
||||
Let's start with the simple case of a single attachment point, called `RightHand`, that is somewhere down the hierarchy of our Player, likely at the end of an arm. In a script that inherits from NetworkBehaviour on the Player Prefab, we'd have a SyncVar enum with various choices of what the player is holding, and a `GameObject` reference where `RightHand` can be assigned in the inspector, and a Hook for the SyncVar to swap out the art of the held item based on the new value.
|
||||
|
||||
In the image below, I've created a simple player capsule with an arm and hand, and I've made some prefabs to be equipped (Ball, Box, Cylinder) and a Player Equip script to handle them.
|
||||
|
||||
**NOTE**: The item prefabs are *art only*...they have no scripts, and they *must not* have networking components. they can have monobehaviour-based scripts, of course, which can be referenced and called from ClientRpc's on the player prefab.
|
||||
|
||||
![Screenshot of Player with Equip Script](ChildObjects1.PNG)
|
||||
|
||||
Here's the Player Equip script to handle the changing of the equipped item:
|
||||
|
||||
```cs
|
||||
``` cs
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user