Let's Make an RPG - ep 17 (NPC and dialogues)
Creating NPCs
In this section, the speaker introduces the topic of creating NPCs and explains how to download and place an NPC in the scene. The speaker also discusses their plans for using NPCs to convey the main story of the game.
Placing and Scaling an NPC
- Download an NPC from the asset store and place it in the scene.
- Scale down the size of the NPC to make it more appropriate for the player's character.
- Adjust animations as needed.
Setting up NPC Interactions
- Create an NPC controller class that listens for input from players.
- Set up a dialogue system using an array of strings and dialogue indices to track progress.
- Allow players to interact with NPCs by clicking on them or pressing a designated button when near them.
Customizing Dialogue
- Customize dialogue options for each individual NPC, either through inspector settings or other means.
- Use dialogue indices to track player progress and unlock new dialogue options as needed.
Setting up Dialog Boxes
In this section, the instructor explains how to set up dialog boxes in Unity using the console. They also discuss creating an input controller to manage all input for the game.
Setting Up Dialog Boxes
- To set up dialog boxes, use the inspector or console.
- Create a void function called "showDialog" with an int parameter that will be used to determine which dialogue is displayed.
- Use "print" to display the dialogue with the index given in the function parameter.
Creating an Input Controller
- Create a new class called "InputController" to manage all input for the game.
- Add this task to Trello and plan on implementing it soon.
- Within the player class, add a physics raycast and create two variables: "ray" and "raycastHit".
- If we hit an NPC with our raycast, get its component NPC controller and show its dialogues using a public function called "showDialogues".
- Create an integer variable for dialog index instead of using an index.
Adding Dialogues
In this section, the instructor adds three dialogues for NPCs and creates a better system for displaying them.
Adding Dialogues
- Change serialize field so that you can change variables within your code.
- Add three different dialogues for NPCs:
- Hi! Nice day!
- What do you need?
- See ya!
Creating a Better System for Displaying Dialogues
- Make an integer public variable called "npcController".
- Check if npcController exists before showing dialogue.
- Instead of calling showDialogue again, get npcController from heat transform.
Checking Dialogue Index
In this section, the speaker explains how to check if the dialogue index is greater than dialogues dot length minus one and set it equal to this.
Checking Dialogue Index
- An array with three values will cause an error when reaching four.
- Check if dialogue index is greater than dialogues dot length minus one.
- Set the dialogue index equals to this.
Printing NPC Name
In this section, the speaker explains how to print the name of the NPC who is talking and then do the talking.
Printing NPC Name
- Print NPC name using concatenation plus sign.
- Show name plus this.
Fixing Errors in Code
In this section, the speaker realizes that they made a mistake in placing else/if. They fix it by returning after doing that.
Fixing Errors in Code
- Place else/if correctly.
- Return after doing that.
Adding Dialogue Box
In this section, the speaker explains how they need a dialogue box for most of the NPCs. They also provide a link to their video on making a typewriter effect for dialogue boxes.
Adding Dialogue Box
- Need a dialogue box for most NPCs.
- Provide link to video on making typewriter effect for dialogue boxes.
Conclusion and Call-to-action
In this section, the speaker concludes by thanking viewers for watching and encourages them to support their work through Patreon or by liking, sharing, commenting on their videos.
Conclusion and Call-to-action
- Thank viewers for watching.
- Encourage support through Patreon or liking, sharing, commenting on videos.