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

KridaFans Partners with Polygon Studio

Sorting Algorithms: Slowest to Fastest

Bringing collaborative editing to any application

3 Ways Your Small Business Can Use Cloud Software

Array iteration performance in C# — Branching and parallelization

Get started with Machine Learning on AWS

How Much Does it Cost to Create a Travel App in 2021

The most valuable cloud management platform for DevOps

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

Giving the enemies some teeth

Creating Double Jump!

Infinite Runner in 3 Steps

Day 101: Character Animation Part 4