First of all, of course, you have to create the levels for your game. Create a separate scene for the credits or credits.
Create a new scene via File -> New Scene. Press Ctrl + N and right-click on UI in the hierarchy window. Create a panel with the UI and switch to 2D mode. Center your panel with F.
Remove the source image and set it from Background to None. Set it to non-transparent. Name the panel as credits. Create another UI element -> Text. Center the text again after setting the margins. Set the Scale Mode under Canvas to Scale with Screen Size.
Drag the text object up and name it. Now you can create a button that will allow you to exit the game.
To do this, choose UI -> Button
Set the source image to None. Add "Shadow" as a new component.
For example, if you set X to 0 and Y to -2 for the shadow, it looks like this.
When the alpha value is reduced, it changes as follows:
Also adjust the buton text. Don't forget to adjust the font too.
Now the button needs a script. Name the script Credits and open it in Visual Studio for editing.
To quit the game you need the following script:
This only works on closing the game if it has been exported. Debug.Log shows you in Unity that it would close.
You also have to drag the credits into the On Click area and assign the function to end the game.
Copy the scene with Ctrl + D and rename it in Menu. Change the settings to a welcome screen and the button from Quit to Start. Remove the credits script from the welcome object.
Add a new script called Menu.
Create a script that starts the game.
You need the following script to start the game:
Drag “Welcome” into the On Click event. If it's not there, open it with the + sign.
Drag the object with the script into the On Click function and select Menu.Start Game to start the game.
Add the scenes including the menu and the credits to the Build Settings.
Originally posted on 2020-06-11 20:54:00.