Learn how to open the message window in the game. You’ll learn how to connect the window into the window manager from Jesse’s Unity 5: Advanced UI course. By adding the new window to the window manager you’ll be able to easily display the message window whenever you need to update the player as to what is happening inside of the game.
- [Voiceover] Now it's time for us to add our message window to the window manager. Inside of our advanced UI folder, go to scripts and windows folder right click and create a new C# script. We're gonna call this message window. Then let's open this up in MonoDevelop. Just like we did with our game window, let's extend the generic window class. We'll also delete the start and update methods and save our class.
Let's go back into Unity, and inside of our Canvas, GameWindow game objects, select the message window. Here, we're going to add our message window component. Next, inside of the Canvas, go to the window manager, add a new window and drag the message window over. We'll also want to create a new enum for the window we just added. Make sure we save this in Assets, AdvancedUI, Scripts, Windows folder.
And hit save, here we can override the existing WindowEnums.cs file, just like we did before. Now let's go ahead and test this out. If we run the game, you'll see that the message window automatically disappears. And this is because all windows turn themselves off as soon as the game starts up. Let's add the ability to open the message window from our random map tester class. Here in the search box, I'll simply start typing out random and choose the random map tester script and open it up in MonoDevelop.
Towards the top of our script, below where we set up the private fields, let's create a new property. We'll make this public, each return type will be WindowManager, and we'll call it windowManager. We'll use a getter and here where we turn our reference to the generic windows static manager field. Now let's scroll down to our tile action callback. Our tile action callback happens whenever the player lands on a tile.
After we call visit tile, we're gonna want to open up the message window, let's access the windowManager and call Open. Now in order for us to open a window, we're gonna need the pass and ID for that window. Luckily we can use the enum that we generated to get that ID. We'll first need to cast it as an int, then we can use the window's enum and select our message window. One thing to note though when we're using the enum is that whenever we open a window this way, we need to subtract one from the value.
And that's because the first item in the enum is always gonna be set to none. Once we're done, let's save this and go back into our game. If we run our game, you'll see that everything shuts itself off. And that's because as soon as the player lands on the castle tile, the message window is called. But the window manager automatically closes any other windows that are open. And since the game window was open and the message window belongs to the game window.
It shut both windows off. We'll need to add some additional logic to the window manager in order to support nested windows like this.
- Preparing the user interface
- Creating game and message windows
- Building a battle window
- Adding a monster and action buttons
- Creating an actor class
- Adding player and monster attack actions
- Triggering battles from the map
- Ending a battle
- Cleaning up the battle and attack systems
- Rewarding the player