From 8ff560fedf3316763cb4291dbf9ad751789e64d7 Mon Sep 17 00:00:00 2001 From: Chris Langsenkamp Date: Thu, 29 Aug 2019 02:33:26 -0400 Subject: [PATCH] Updated PickupDropChild doc --- .../Concepts/GameObjects/PickupDropChild.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/articles/Concepts/GameObjects/PickupDropChild.md b/doc/articles/Concepts/GameObjects/PickupDropChild.md index 9ec951354..9234fce23 100644 --- a/doc/articles/Concepts/GameObjects/PickupDropChild.md +++ b/doc/articles/Concepts/GameObjects/PickupDropChild.md @@ -22,7 +22,7 @@ Below is the Player Equip script to handle the changing of the equipped item, an - The example makes no effort to deal with position offset between the item and the attach point, e.g. having the grip or handle of an item align with the hand. This is best dealt with in a monobehaviour script on the item that has public fields for the local position and rotation that can be set in the designer and a bit of code in Start to apply those values in local coordinates relative to the parent attach point. -``` cs +```cs using UnityEngine; using Mirror; @@ -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().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)