How to Make an Adventure Game Like King’s Quest

In this tutorial you will learn how to implement the core functionality of text-based games like King’s Quest I using Unity. By Najmm Shora.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Scene Interaction Setup

First, attach Interactable Object to the following GameObjects:

  • Apples
  • Bucket
  • Rope

Hierarchy selections for InteractableObject component

Then select InputField and add the GameManager.ExecuteCommand to the subscriber list for its On End Edit event as shown below:

adding executecommand to the on end edit event.

This ensures GameManager.ExecuteCommand is called when the player presses the Return key after typing the command.

Now select the Main Camera.

Set the size of Object Array of the Game Manager to 3.

You’ll need to set each element of Object Array‘s Interactable Object field to Apples, Bucket, and Rope respectively.

Each should then have it’s own Names array set with variations of what it could be called. For example Apples could be referred to as either “Apple” or “Apples”.

You should end up with a configuration as shown in the following screenshot:

Inspector for Main Camera

Next, select Bucket and set its Interactable Object properties as follows:

Set the Size of States to 1. Change Identifier to default and Look Dialogue to the string That’s one huge bucket..

Change Is Available to false (i.e. unchecked).

Here is how it should look:

Inspector for Bucket

Then select Apples and set its Interactable Object properties as follows:

  • Set Away Min Distance to 4.
  • Changes States Size to 1.
  • Under States, set the Identifier to default and Look Dialogue to the string “The ground near the tree is covered with lots of apples.”
  • Change the Size of World Interactions to 1.
  • Set the Size of Verbs under World Interactions to 2.
  • Enter the verbs pick and get for the two verb elements.
  • Now set the Dialogue and Away Dialogue to “You picked up a delicious apple.” and “I need to get near the apples first.” respectively.

Notice how you’re using get and pick for the same interaction. Also, notice the use of Away Min Distance to configure the difference between the normal dialogue response and the away dialogue response.

Inspector for apples

Finally, select Rope and set its Interactable Object properties to react to the inside and pull identifiers. The setup of this Interactable Object component is similar to how you configured Apples, except you’ll also be adding 5 Actions in this case.

The Rope Interactable Object component should end up configured like this:

Inpsector for rope

Notice you’re changing the state of the rope after the pull. Also notice how the Bucket is made available for interactions after the pull interaction.

Save everything and Play. Type the commands inside the input field and test them. For the existing setup try:

  • look at the rope
  • pull the rope
  • look at the apples
  • pick up an apple
  • look at the bucket

Preview of finished tutorial

You can also try some variations on these, such as:

  • look at rope
  • pull rope
  • get an apple
  • get the apples
  • look at the large bucket

That’s it!

Where to Go From Here?

You can download the final project by using the Download Materials button at the top and bottom of this tutorial.

Try adding your own interactions. There are a bunch of unused objects in the scene. You can create a story with these.

You can also explore the Final project and take a look at the Final scene inside RW/Scenes where a bit of a story has been added. You can see how the interactions are setup.

As you might have noticed, you’re currently using existing methods or properties inside the Unity Editor to set up interactions. You can program custom methods and also subscribe to the interaction events in other ways. You can also add more scenes and add scene transitions.

Look at the original manual for King’s Quest I and see if you can replicate all the game features.

Thanks for taking the time to read this tutorial. I hope you had fun and learned something new. Please feel free to join the forum below for any questions or comments.