Use the Escape button to exit a game in Unity

It is critical to have an exit button coded in the game so that one can walk out without turning off the computer and at times, mood.

This task can not get any simpler than this :)

However, please make sure that a game manager script is in place that takes care of shifting in between scenes of the game.

  • In the update method, write an if statement which checks for the escape keypress.
  • Unity has a special command that does the rest of the job.
C#
  • The scripting reference is here from Unity.
  • Save the script and go back to the game to verify the exit part being taken care of :)

Thank you very much

--

--

--

Work in Progress.

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

Recommended from Medium

Azure Functions — Part 2

How we built passwordless authentication with Auth0 and Elixir/Phoenix

Tatum now supports Solana!

Explaining Micro Frontends Using the Fathym Arcade

Head First Java-Chapter 4

Why Kubernetes is Not a Silver Bullet

Introducing Symfony Panther: a Browser Testing and Web Scrapping Library for PHP

Migrate Git Repository Without Losing History

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
Samarth Dhroov

Samarth Dhroov

Work in Progress.

More from Medium

When to use On Collision or On Trigger

Switch Statements To The Rescue!

Scene Loading — Restarting our game

Creating a material in Unity