The Escape Button is a Feature

Day 33- Making 2D Space Shooter Game

Objective: Add a escape functionality in your game.

As much as it is interesting and fun to play a game, it is equally important to have a way to exit them if needed.

What is a game without a exit, it simply becomes prison for continuous gaming and gets uninteresting. So we are going to add a escape using escape key which will take you to the main screen and there you can decide if you want to play a game again or exit a game using exit game button.

Enter this line of code in your UIManager script or other script which holds similar functionalities and it will take you to the main menu whenever you press escape key.

Note: Make sure the index for Main Menu scene is 0.

Then write this method in your main menu script which holds the function for New game button as well.

Copy-Paste your New game button and rename it to quit game. Then position it to your liking.

Finally change your On click inside button from New Game to Quit game and you have successfully created a Escape functionality in your game.




Unity Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bootstrapping Hibernate 4 with Spring | Code Factory

ARC product development update

Why to use Ionic 6 and Phaser 3?

How to make a header or footer cover the entire width of the page

Microservice Architecture

Journey of DLithe Bootcamp .NET Full Stack Week 2(Jan31-Feb5)

Productivity in Learning with fluany

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Niraj Karki

Niraj Karki

Unity Developer

More from Medium

Creating Character Animations in Timeline and Tackling Some Known Issues

Prefab dependency injection in Unity

Creating a Sci-fi Lab Room

Unity — new input system create an action map