/ Function called when Replay button is clicked in Game Over / Summary view. Owner.UI.GameOverView.OnMenuClicked -= MenuClicked Owner.UI.GameOverView.OnRepla圜licked -= Repla圜licked Owner.UI.GameOverView.OnMenuClicked += MenuClicked
Owner.UI.GameOverView.OnRepla圜licked += Repla圜licked Data with information about game result / It shows how you can handle data with game result and display it in UI view. By default, all new C scripts include the System.Collections. Namespaces are accessed at the top of a script with the using keyword. As the state is enabled, we are passing that data to UI to be displayed. When you include a namespace in your class, you are stating that you want to access all the variables and methods (functions) in your class. This one stores information about a game result which is just a simple class that stores random score here. Owner.ChangeState(new GameOverState ) Īnd the last state that we have to speak about is GameOverState.
Used when player decide to go to menu from pause state Variables used for loading and destroying game content / It shows game view and can load some content related to gameplay. In my example, I have none of the above, so I’ve just left space for it in PrepareState to load, and in DestroyState I left space to destroy not needed content. Game State is just a little different because, in your project, you would need to load some levels or enemies, so there is something to do in your game. And this is true for every other state here. Isn’t it beautiful? On State Start, we are attaching functions to UI events, and they are connected until we change state. / Function called when Quit button is clicked in Menu view. / Function called when Start button is clicked in Menu view. Owner.UI.MenuView.OnQuitClicked -= QuitClicked Owner.UI.MenuView.OnStartClicked -= StartClicked Owner.UI.MenuView.OnQuitClicked += QuitClicked Owner.UI.MenuView.OnStartClicked += StartClicked / Menu state that show Menu view and add interpret user interaction with that view. So what makes that approach so special? Most importantly, logic is implemented on the state-side where it belongs. Rest of the UI scripts are available at the end of the post in public repository. To show you what I mean by that, here is the implementation of MenuView: This practice comes from one of the pillars of MVC, but I’m not going to speak about it now. Their only purpose is to display view and pass user interactions to the states. So first thing before we jump into those states, I’ve implemented UI views to make them as independent as I could.