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.



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