mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Updated PickupDropChild doc
This commit is contained in:
parent
8614d3f913
commit
8ff560fedf
@ -94,7 +94,7 @@ Now that we can equip the items, we need a way to drop the current item into the
|
||||
|
||||
First, let's add one more Input to the Update method above, and a `CmdDropItem` method:
|
||||
|
||||
```
|
||||
```cs
|
||||
void Update()
|
||||
{
|
||||
if (!isLocalPlayer) return;
|
||||
@ -113,7 +113,7 @@ First, let's add one more Input to the Update method above, and a `CmdDropItem`
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
```cs
|
||||
[Command]
|
||||
void CmdDropItem()
|
||||
{
|
||||
@ -139,7 +139,7 @@ First, let's add one more Input to the Update method above, and a `CmdDropItem`
|
||||
|
||||
In the image above, there's a `sceneObjectPrefab` field that is assigned to a prefab that will act as a container for our item prefabs. The SceneObject prefab has a SceneObject script with a SyncVar like the Player Equip script, and a SetEquippedItem method that takes the shared enum value as a parameter.
|
||||
|
||||
```
|
||||
```cs
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
@ -183,13 +183,13 @@ public class SceneObject : NetworkBehaviour
|
||||
|
||||
In the run-time image below, the Ball(Clone) is attached to the `RightHand` object, and the Box(Clone) is attached to the SceneObject(Clone), which is shown in the inspector.
|
||||
|
||||
![](ChildObjects2.PNG)
|
||||
![Screenshot of Kyle with equipped item and scene object](ChildObjects2.PNG)
|
||||
|
||||
## Pickup Items
|
||||
|
||||
Now that we have a box dropped in the scene, we need to pick it up again. To do that, a `CmdPickupItem` method is added to the Player Equip script:
|
||||
|
||||
```
|
||||
```cs
|
||||
// CmdPickupItem is public because it's called from a script on the SceneObject
|
||||
[Command]
|
||||
public void CmdPickupItem(GameObject sceneObject)
|
||||
@ -204,7 +204,7 @@ Now that we have a box dropped in the scene, we need to pick it up again. To do
|
||||
|
||||
This method is simply called from `OnMouseDown` in the Scene Object script:
|
||||
|
||||
```
|
||||
```cs
|
||||
void OnMouseDown()
|
||||
{
|
||||
NetworkClient.connection.playerController.GetComponent<PlayerEquip>().CmdPickupItem(gameObject);
|
||||
@ -215,4 +215,4 @@ Since the SceneObject(Clone) is networked, we can pass it directly through to `C
|
||||
|
||||
For this entire example, the only prefab that needs to be registered with Network Manager besides the Player is the SceneObject prefab.
|
||||
|
||||
![](ChildObjects3.PNG)
|
||||
![Screenshot of inspector](ChildObjects3.PNG)
|
||||
|
Loading…
Reference in New Issue
Block a user