Updated PickupDropChild doc

This commit is contained in:
Chris Langsenkamp 2019-08-29 02:33:26 -04:00
parent 8614d3f913
commit 8ff560fedf

View File

@ -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. - 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 UnityEngine;
using Mirror; 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: First, let's add one more Input to the Update method above, and a `CmdDropItem` method:
``` ```cs
void Update() void Update()
{ {
if (!isLocalPlayer) return; if (!isLocalPlayer) return;
@ -113,7 +113,7 @@ First, let's add one more Input to the Update method above, and a `CmdDropItem`
} }
``` ```
``` ```cs
[Command] [Command]
void CmdDropItem() 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. 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 UnityEngine;
using Mirror; 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. 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 ## 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: 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 // CmdPickupItem is public because it's called from a script on the SceneObject
[Command] [Command]
public void CmdPickupItem(GameObject sceneObject) 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: This method is simply called from `OnMouseDown` in the Scene Object script:
``` ```cs
void OnMouseDown() void OnMouseDown()
{ {
NetworkClient.connection.playerController.GetComponent<PlayerEquip>().CmdPickupItem(gameObject); 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. 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)