In this lecture, will explore the implementation of the menu system in the feed the teddies game. As you can see in my project, I have a high score menu Prefab and a pause menu Prefab and we also have a separate scene for the difficulty menu and a separate scene for the main menu, And of course scripts to help support our menu system of functionality. Well look at how the menu system works first and then we'll look at the code that makes it all happen. My main menu has a high score button that if I click tells me the high score that I have so far playing this game. So I have a massively high score of 20 in the game and the quit button that brings us back to the main menu. I have a quit button that in a built game will actually quit the unity player. And I have a play button that brings me to a difficulty menu for easy, medium or hard. And if I pick an easy game for example and start playing and then hit escape, I get my standard pause menu and I can resume my game or I can quit back to the main menu. Now that we've seen how the menu system works, let's go take a look at the code. I have a menu name enumeration and this enumeration lists all the names of the different menus I have in my game. I have a difficulty menu, a high score menu, a main menu and a pause menu. The menu manager class and the feed the teddies game is very similar to the menu manager I showed you previously. It's a static class with a single static method called go to menu and we pass in the menu name we want to go to. If we want to go to the difficulty menu, I load the scene for the difficulty menu, that's a separate scene that I showed you in the unity editor. If we want to go to the high score menu, I do a couple of things here and it's important to note that we can go to the high score menu either from the main menu as I demonstrated or from the gameplay scene when the game finishes. So the first thing I do is I look for the main menu canvas. If the main menu canvas isn't now, then I deactivate it. I call the set active method on the main menu canvas game object and set that game object to be inactive. That's why I pass in false as the argument. So this is to handle if I'm going to the high score menu from the main menu. If I'm going to the high score menu from the gameplay scene, main menu canvas will be null, so I won't do this code. After I've deactivated the main menu canvas, I then instantiate my high score menu Prefab. If I say I want to go to the main menu, I just load the main menu scene and as we've seen before with the pause menu, if I want to go to the pause menu I just instantiate the pause menu that I load from the resources folder. In my main menu class, if the player clicks the play button, I do a couple of things. First I play a sound effect and we'll look at the sound effects and feed the teddies in a later lecture. And then I called the menu manager go to menu method saying go to the difficulty menu. So in defeat the teddies game as I showed when the player clicks the play button, they go to the difficulty menu. If they click the high score button, I play a sound effect and then I go to the high score menu. And if they click the quit button, I play a sound effect and I use the application quit method as we've seen before for a quit button in the menu to actually quit out of the build unity game. Remember that doesn't work in the editor but it works if we build the game and play it. Notice that the difficulty menu class inherits from the intevent invoelker class that we talked about in the previous lecture. So the difficulty menu is an invoker for a unity event with one intparameter. In the start method for the difficulty menu, I add a new game started event, that's the event that I'm going to invoke from the difficulty menu to the dictionary of unity events that I inherited from intevent invoker and I put the key as the game started event name. So this creates a new game started event object and adds it to my Unity Events dictionary for this particular class for the game started event. I also then add myself to the event manager as an invoker of the game started event passing myself in as the invoker. And I can pass myself in even though I'm a difficulty menu because I have that is a relationship with event invoker. A difficulty menu is a intevent intinvoker even though that's bad grammar because the second parameter for the add invoker method in the event manager is an intevent invoker object, this all works fine. If the player clicks the easy button, I play a sound effect and then I access within my Unity Events dictionary, the value the event that is keyed by game started event and I invoke that event with the easy difficulty. But this is an enumeration value in the difficulty enumeration and we know we can only pass an int when we invoke this event so I just cast it to an int. And I can do that because under the covers, enumeration actually are ints, so this is a valid cast and I just cast the difficulty enumeration value to an int. If I click the medium button, I invoke the event with a medium value and if I click the hard button I invoke the event with a hard value. In my high score menu, within start, I pause the game and I need to do this just in case this is happening from within the gameplay scene. It doesn't really have any effect within the main menu scene but within the gameplay scene, if the game finishes, I want to pause the game without opening up the pause menu to display the high score menu. So this pauses the game, and then I use player press to check to see if I've saved a high score in the past. And if I have, then I retrieve that high score and I added to the message in the high score menu. If I look for this key and it doesn't exist in player prefs, that means that I haven't actually played the game yet. So instead of displaying your high score and a particular score, I say high score, no games played yet. So this is the message that will appear in the high score menu if I went to it from the main menu before ever playing the game at all. When the player clicks the quit button on the high score menu, I play a sound effect, I unpause the game and I go back to the main menu. And finally, the pause menu is identical to the pause menus we've looked at before, so on start I set time scale to zero. If the player clicks the resume button, I play a sound effect unpause the game and destroy the game object, so I'm staying in the gameplay scene and just unpaused the game and the player keeps playing. But if the player clicks the quit button, I play a sound effect unpause the game, I destroy the pause menu and I go back to the main menu, and that's how the menu system works in the feed the teddies game. To recap, in this lecture, you learned how to use a menu manager to implement a slightly more complex menu system.