Create great GAME OVER screen in Unity UI - Unity tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] games would look terrible without the game over screens of course we hate seeing them but they often allows us to restart the game or load the last save but today i'll show you how to create a simple game over screen in unt where you'll be able to express your creativity and add some functionality to your game let's start by creating a dark background on top of our game right click anywhere in the hierarchy and select ui image we can manually resize it to fill the entire screen but the best way to do it is to click on this anchor presets button and while holding alt or option key click on this double stretch option then rename it to background and finally set the image color to black with some transparency great next time to create a game over text right click on the background and select ui text i'll start by changing its position in size then i'll change its value to game over select font font size in my case 32 alignment to center middle and finally color to white because on the game over screens you often see a final score of the game i'll just duplicate this text move it a bit down change its value to something like 10 points make it a bit smaller and change its color to yellow for example the last missing puzzle are the buttons again right click on the background and select ui button i'll simply move it down change color to also yellow and its text to restart don't forget about the font consistency finally just duplicate the newly created button change its color to blue and its text to main menu great this is already some nice looking game over screen now let's code it i'll click on the background component and then the add component button here we'll create a new script called game over screen open it and here instead of the start and update methods i'll type public void setup that gets one parameter int score open brackets that method will be triggered from the other script to open the game over screen firstly to show this screen we'll need to type gameobject dot set active true then we need to assign score to the text to work with the unity y at the very top type using unity engine dot ui and then create a new variable public text points text to modify it in the setup method simply type points text dot text equals score dot tostring plus points great we can now test it out i have a game control script where i'll add a new public variable of the game over screen type called simply game over script this gameover method is called whenever john loses so let's use it and type gameoverscreen dot setup and pass in points in my case max platform time to save everything go back to unity and assign points text in game over screen script and game over screen object so background in the game controller script lastly to hide the game over screen at the beginning of the game simply uncheck background visibility let's run the game jump a few platforms and here is our wonderful game over screen it correctly shows points but buttons don't do much so let's fix that back to our game over script let's start by creating the public methods public void restart button and public void exit button here we'll be restarting the current screen but before we can do that we need to type at the very top using unity engine that scene management then in the first method type scene manager dot load scene and passing the name of our scene in my case game in the exit button we'll use the same line but this time i'll type in a main menu scene save everything and in unity select both buttons click on this plus icon in on click event drag in the background object and now select for the first button game over screen restart button and for the second one game over screen exit button great time to test everything out i'll press play jump a few platforms jump off them and on our game screen press restart it works in fact when i try that again we can go even to the main menu i've created in the previous episode and that's everything i have for you today if you have any unity related questions be sure to ask them in the comments and maybe i'll answer them in the next video also be sure to join coco code discord and to subscribe for more tutorials see you around
Info
Channel: Coco Code
Views: 60,928
Rating: undefined out of 5
Keywords: unity, cococode, bionicl code, bionicl, unity3d, Maciej maj, tutorial, guide, coco code, game over, game over screen, game over screen unity, game over in Unity, Game over screen in Unity, How to restart level in Unity, How to go back to game in Unity, game over try again, end of the game, finish game in Unity, Player loose in Unity, End game in Unity, Unity end game, Unity game over
Id: K4uOjb5p3Io
Channel Id: undefined
Length: 6min 26sec (386 seconds)
Published: Thu Dec 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.