Adding a pause button to the startScene
Since we are in startScene, let's add one more type of button, called a toggle button, to pause or unpause the game.
Go to GameObject
| UI
and create a new toggle button. Once created, position it at the top right of the game screen. Rename the button to pauseBtn
.
Like other buttons and UI elements, it has a Rect Transform
section which can be used to position the button:
It also has a Toggle (Script)
which can be set to the default values. Select the Background
tab, to choose the background image to be used for the button.
In the Image (Script)
under Background
, select the pauseBtnOff
 Sprite type as the background image:
There is also a label tab for any text script, which you can leave blank as we will only be using the image.
Whenever you click the button, it will create a tick mark over the pause image to specify that the button is toggled. If you click on it again it will revert to the usual image.
Now, in the gameScript
file, we create a public variable...