Quest System | Unity Tutorial

Quest System | Unity Tutorial

Creating a Quest System in Unity

In this video, the presenter shows how to create a simple quest system in Unity. The objective is to find a key and unlock a door. The presenter also invites viewers to request more videos on creating quests or other topics.

Setting up the Scene

  • The scene consists of a level asset from the Unity Asset Store, with a closed door that requires a key to open.
  • A key block object is placed in the scene, which can be picked up by the player.
  • A cube object is added as a child of the key block object and set as a trigger collider.

Writing Code for Objectives

  • A C# script is created for the trigger collider on the key block object.
  • A public game object variable is created for the door animation, which will be accessed when the player finds the key.
  • A private static boolean variable called "isFound" is created and set to false at first.
  • An if statement checks if another game object with tag "Player" enters the trigger collider. If so, it checks if "isFound" is false and displays an objective UI element telling players to find the key.

Updating Objectives When Key Is Found

  • Another public game object variable is created for displaying text when players find the key.
  • When players pick up the key, "isFound" becomes true and updates the objective UI element to tell players to unlock the door.
  • When players approach the door with the key, an animation is played and the door opens.

Conclusion

  • The presenter encourages viewers to expand on this simple quest system and create more complex objectives.

Creating a UI Objective to Get the Key

In this section, the speaker creates a UI objective for the player to get the key needed to unlock a door.

Creating a Canvas and Text Mesh Pro Object

  • Create a canvas object and add a Text Mesh Pro component to it.
  • Name the text object "Get Key Objective".

Adding the UI Objective to the Trigger

  • Drag and drop the canvas object with the "Get Key Objective" text into the trigger.
  • Ensure that the player is tagged as "player".

Writing Code for Picking Up the Key

  • Write code in C# script called "PickUpKey.cs".
  • Add an if statement that checks if other game objects with tag "player" are colliding with this trigger. If true, check if input button "F" is pressed.
  • Create a reference variable for the key object.
  • Set active false for key object when picked up by player.

Disabling UI Objective After Getting Key

  • Copy and paste previous code block from PickUpKey.cs script.
  • Set active false for canvas object after picking up key.

Unlocking the Door

In this section, the speaker demonstrates how to unlock a door in Unity using code and animations.

Finding the Key

  • The player must find the key to unlock the door.
  • The key is located in a maze filled with enemies.

Unlocking the Door

  • Once the key is found, the player can go back to the door and unlock it.
  • A UI element disappears once the door is unlocked.

Writing Code for Unlocking Door

  • Add another camera and write code to unlock door.
  • Use underscore text back in start function and do not set active false.
  • Copy same code and set it to true for unlocking door.

Updating Objective Text

  • Update objective text when unlocking door by changing "get key" to "unlock door".

Animating Door Opening

  • Create an animation for opening the door called "Open Door".
  • Add a trigger parameter called "Open Door" and make a transition from idle state to open state.
  • Set Open Door parameter off loop so that it doesn't keep opening and closing repeatedly.

Adding Input for Opening Door

  • Add input for opening door using E key by adding if statement in trigger function.

Adding UI Elements

In this section, the speaker adds UI elements to the game to provide indications to the player.

Adding Use Key Text

  • The speaker adds a new UI element called "Use" and sets its text to "Press E to unlock door".
  • The code for the "Use" key is copied and pasted into another object.
  • The speaker explains that this is done so that objects can be shown more clearly to the player.
  • The code for setting the "Use" key text to true when entering a trigger and false after pressing E is added.

Adding Pick Up Key Text

  • The speaker adds another UI element called "Pick Up Key" with text "Press E to pick up the key".
  • Code for showing and hiding the "Pick Up Key" text is added.
  • The code for setting the "Pick Up Key" text to true when entering a trigger and false after picking up the key is added.

Fixing Bugs

In this section, the speaker fixes bugs related to displaying UI elements.

Fixing Show Once Bug

  • The speaker identifies a bug where if an object has been found once, its corresponding UI element will remain visible even if it should not be.
  • A private bool variable called showOnce is created and set as false.
  • Code for showing an object's corresponding UI element only once until it disappears or resets is added.

Unlocking the Door

In this section, the speaker demonstrates how to unlock a door in a game by picking up a key and using it to disable a force field.

Picking Up the Key

  • To pick up the key, press E.
  • The key is needed to unlock the door.

Disabling the Force Field

  • Disable the force field by pressing specific buttons on nearby computers.
  • The process can be turned into a riddle for added challenge.
  • If done incorrectly, an error message will appear and players must try again.

Expanding the Game

In this section, the speaker discusses potential ways to expand upon the game's mechanics and challenges.

Adding a Riddle Element

  • A magical sphere could surround the key, requiring players to solve a riddle before they can pick it up.
  • Players would need to disable the sphere by pressing specific buttons on nearby computers in order to obtain the key.

Request for Feedback

  • The speaker asks viewers if they would like to see these changes implemented in future videos.
  • If 15 likes are received, he will create an expanded video with these features.

Conclusion

In this section, the speaker concludes his video and thanks viewers for watching.

Final Thoughts

  • The speaker hopes that viewers enjoyed and learned from his video.
  • He invites feedback and suggestions for future content.

Closing Remarks

  • The speaker signs off with "peace".
Video description

Subscribe & Like for more Content like this. ------------------------------------------- Youtube : https://www.youtube.com/c/GunzzYT twitch : https://www.twitch.tv/gunzz___