Creating an NPC
Learn how to create NPCs from ZEPETO Characters.
Apply the sample scripts provided for each feature to add the NPC of your choice to your World.
Create an NPC using a ZEPETO ID.
- The NPC's appearance and items worn will be the same as the ZEPETO ID entered.
- It is recommended that you set up a ZEPETO character with a specific appearance before creating an NPC.
- Implement the ZEPETO character creation code in your Scene by default.
📘 Please refer to the following guide. [Create a ZEPETO Character]
- Create Hierarchy > Create Empty Object and rename it to NPC.
- An object to store the location where the NPC will be created.
- Set the Position, Rotation.
1) Create Project > Create > ZEPETO > TypeScript and rename it to NPCCreator.
2) Write a sample script like below.
The flow of the script is as follows:
- Start()
- Create an NPC in the NPC object location using the ZepetoCharacterCreator.CreateByZepetoId() function and save it in _npc.
3) After you have finished writing the script, add the script to the NPC object.
4) Assign the Zepeto Id in the inspector.
- Zepeto Id : The ZEPETO ID of the NPC.
5) Press the play button to execute and the NPC will be created.
6) Add an NPC location object in the same way, and add an NPC script to create multiple NPCs easily.
You can label your NPC with name tags to distinguish them from players.
1) Create a Hierachy > UI > Canvas and rename it PrefNameTagCanvas.
- Set the Render Mode to World Space.
2) Create Hierarchy> UI > Text as a child of PrefNameTagCanvas and rename it to NameTagText.
- The text to represent the name.
- Add a Content Size Fitter component to make the text the right size.
3) Once you're done, drag it to the Project window to make it a Prefab, and then delete the PrefNameTagCanvas that's still in the highlighter.
1) Create a Project > Create > ZEPETO > TypeScript and rename it to NPCCreatorWithNameTag.
2) Write a sample script as shown below.
The flow of the script is as follows:
- Start()
- Call the SetNameTag() custom function.
- SetNameTag()
- Dynamically generates a name tag for the NPC and adjusts the position of the generated name tag above the NPC's head
- Set the text inside the name tag.
- Update()
- Call the UpdateCanvasRotation() custom function to rotate the canvas to match the camera.
3) After you have finished writing the script, add it to the NPC object.
4) In the Inspector, assign the Zepeto Id, Name Tag, Name Tag Prefab, and Name Tag Y Offset.
- Name Tag: The name that will appear on the NPC's name tag.
- Name Tag Prefab: The name tag canvas prefab.
- Name Tag Y Offset: A variable that stores the y-axis offset value for the Name Tag Canvas object. When you place the name tag above the character's head, you can adjust the distance between the character and the name tag.
5) press the play button to execute, and the NPC with the name tag will be created.
You can control the actions of NPC.
Use the ZEPETO Character API to make the NPC jump.
You can use the ZEPETO Character API to implement a wider range of behaviors.
📘 Please refer to the following guide. [ZEPETO Character]
1) Go to Project > Create > ZEPETO > Create TypeScript and rename it to NPCJump.
2) Write a sample script as shown below.
The flow of the script is as follows:
- Start()
- Call the JumpCoroutine() coroutine.
- JumpCoroutine()
- Call the Jump() method to make the NPC character jump every 5 seconds.
3) After you have finished writing the script, add the script to the NPC object.
4) Press the Play button and the NPC will jump.
Use the Animator Controller to implement gestures for NPC.
You can use the Animator Controller to implement a wider variety of behaviors.
📘 Unity Animator Controller https://docs.unity3d.com/Manual/class-AnimatorController.html
- Use the following guide to prepare the gesture animation clip for your NPC to perform.
📘 Please refer to the following guide.
1) Project > Create > Create Animator Controller and rename it to NPCAnimatorController.
2) On the Animator tab, Create State > Empty.
3) In the Inspector, rename it appropriately and assign the animation clip to Motion.
1) Create a Project > Create > ZEPETO > TypeScript and rename it to NPCGesture.
2) Write a sample script as shown below.
The flow of the script is as follows:
- Start()
- Get the Animator component of the NPC object and set it to the Animator Controller specified by the npcAnimator variable.
3) After you finish writing the script, add it to the Location object where the NPC will be created.
4) In the Inspector, assign the Zepeto Id, Npc Animator.
- Npc Animator: The NPC's animation controller.
5) Press the play button to run it and you'll see the NPC make a gesture.
6) You can apply this to create NPCs that do more actions besides gestures and jumps.
You can create a Canvas above an NPC's head, display an image or text, and make it bubble.
1) Create a Hierarchy> UI > Canvas and rename it to PrefSpeechBubbleCanvas.
- Set the Render Mode to World Space.
2) Create a Hierarchy> UI > Image as a child of PrefSpeechBubbleCanvas and rename it to SpeechBubbleImage.
- This is the image that will be the background of the speech bubble.
3) Create Hierarchy> UI > Text as a child of SpeeachBubbleImage and rename it to SpeeachBubbleText.
- This is the text inside the speech bubble.
- Add a Content Size Fitter component to make the text the right size.
4) Once you're done, drag it to the Project window to make it a Prefab, and then delete the PrefSpeechBubbleCanvas that is still in the Highlight.
1) Create a Project > Create > ZEPETO > TypeScript and rename it to NPCSpeechBubble.
2) Write a sample script as shown below.
The flow of the script is as follows:
- Start()
- Call the SetBubble() custom function.
- SetBubble()
- Create a speech bubble canvas (speechBubblePrefab) and position the created speech bubble above the NPC's head
- Call the SetBubbleText() custom function to set the text inside the speech bubble.
- SetBubbleText()
- Activates the NPC's speech bubble canvas (_speechBubbleObject).
- Displays the string given as a parameter (bubbleText) inside the speech bubble.
- Update()
- Call the UpdateCanvasRotation() custom function to rotate the canvas to match the camera.
3) After you have finished writing the script, add it to the Location object where the NPC will be created.
4) In the Inspector, assign the Zepeto Id, Speech Bubble Text, Speech Bubble Prefab, and Speech Bubble Y Offset.
- Speech Bubble Text: This variable stores the dialog that the NPC character will say in the speech bubble. In our example, we store the following dialog: "Hello World".
- Speech Bubble Prefab: This variable stores the prefab for the Speech Bubble Canvas GameObject.
- Speech Bubble Y Offset: This variable stores the y-axis offset value for the Speech Bubble Canvas GameObject. This allows you to adjust the distance between the character and the speech bubble when you place the speech bubble above the character's head.
5) press the play button to execute, and you will see a speech bubble floating above the NPC's head.
You can implement a lot of fun content by interacting with NPCs.
In this guide, we will use an example to implement a speech bubble that changes when an NPC is approached.
1) Add a Collider component to your object to interact with the NPC and check isTrigger.
2) Resize the Collider to the extent that the player can interact with the NPC.
1) Create Project > Create > ZEPETO > TypeScript and rename it to NPCInteraction.
2) Write a sample script as shown below.
The flow of the script is as follows:
- OnTriggerEnter(), OnTriggerExit()
- When the trigger is detected by entering the collider area, call the SetBubbleText() custom function to set the text inside the speech bubble to changedSpeechBubbleText.
- When it leaves the collider area, call the SetBubbleText() custom function to set the text inside the speech bubble to speechBubbleText.
3) After you have finished writing the script, add it to the Location object where the NPC will be created.
4) In the Inspector, assign the Zepeto Id, Speech Bubble Text, Speech Bubble Prefab, Speech Bubble Y Offset, and Changed Speech Bubble.
- Speech Bubble Text: This variable stores the dialog that the NPC character will say in the speech bubble. In our example, we store the following dialog: "Hello World".
- Speech Bubble Prefab: This variable stores the prefab for the Speech Bubble Canvas GameObject.
- Speech Bubble Y Offset: This variable stores the y-axis offset value for the Speech Bubble Canvas GameObject. This allows you to adjust the distance between the character and the speech bubble when placing the speech bubble above the character's head.
- Changed Speech Bubble: Stores the dialog that will be displayed in the NPC's speech bubble when the player enters the NPC's collider.
5) press play to execute, and when the player approaches the NPC, the text in the speech bubble will change.
To create a dialog format, create a UI using a panel.
The following is an example of a simple dialog composed of panels and buttons.
This is an example script that opens dialogs when interacting with NPCs and processes them when each button is pressed.
Apply this to implement interesting content.