Attaching objects to ZEPETO characters
Attach an object to a ZEPETO character so that when the character moves, the object moves with it.
First, you need to turn your object into Prefab. Create an object, drag it to the Asset folder and make it a Prefab.
- Implement the ZEPETO character creation code in Scene as a default.
📘 Please refer to the following guide. [Create a ZEPETO Character]
1) Create Hierarchy > Create Empty Object and rename it to AttachObject.
2) Create Project > Create > ZEPETO > TypeScript and rename it to AttachObject.
3) Write a sample script like below.
- The script flows as follows:
- Start()
- Register the ZepetoPlayers.instance.OnAddedLocalPlayer event listener, which will fire when a local player is added.
- Set the local player to the _localCharacter variable.
- Get the animator component of _localCharacter, get the location specified in bodyBone, and create the prefab specified in prefItem at that location.
1) After finishing writing the script, add the script to the AttachObject object.
2) In the Inspector, assign the Pref Item, Body Bone.
- Pref Item is the object prefab.
- Body Bone is the location where the object will be created.
- Select LeftHand to make it look like you are holding the object in your hand.
3) Press the Play button to run and you will see the ZEPETO character with the object attached to his left hand.
You can attach any object to the desired location of the Body Bone in the same way.
📘 Unity HumanBodyBones https://docs.unity3d.com/ScriptReference/HumanBodyBones.html
The following is an example of attaching a Neck Pillow object from BuildIt to the character's neck to make it look like the ZEPETO character is wearing a neck pillow.
- You can adjust the Position and Rotation of the object appropriately to get the desired look.
- In the Inspector, assign the Neck Pillow object to the Pref Item, and select Neck for the Body Bone.