Scripting Time! Transmutation: Menus

03 Aug

Transmutation Main Menu.JPG

I’m no stranger when it comes to making menus. In my ‘Ball Ball Post Mortem‘ I noted that I made a huge mistake of constructing the game in the free aspect mode. I wasn’t going to let this cause me havoc again. So before I started creating any form of UI, I set the aspect mode to 16:9 and made sure that the UI Canvas scaler was set to scale with screen size.

Transmutation Main Menu Red.png

For the simple main menu of Transmutation all that we needed was a play button, instructions button, quit button and an exit instructions button and the code that would make the buttons do what they are supposed to do. The only difference with Transmutation and other menus that I’m used to creating is that Transmutation is going to be solely operated by a controller, not mouse and keyboard. One of the programmer’s had already set up the controller and mapped the inputs for using the left joystick.

Something new that I had to learn was how to get the buttons to be selected with the controller input. I’ve noticed that when I create a UI canvas, an EventSystem always gets created as well. I did some research and watched tutorials on how to make menus work with controllers and it turns out all I had to do (because the left joystick was already set up) was make the FirstSelected object in the EventSystem what I wanted. And I wanted the first selected button to be the Play Button.

First Selected.JPG

I hit the play button and waited for the magic to happen. But no magic was happening. I wondered why and fiddled with some of the buttons settings. Eventually I made the buttons highlight colour when they were selected a bright yellow.

Transmutaiton Yellow Highlight

Because the buttons navigation was set to automatic – they detect where they can go from their position – and the buttons were always directly above or beneath each other they could only ever navigate vertically. Which was the desired effect anyway.

Button Visualize.JPG

The Yellow Arrows Show Where They Can Navigate To

The instructions button brings up a separate panel for the controller. And now that writing that makes me realize shouldn’t the instructions be called Controls? Yes. ANYWHO.

Instructions Panel.JPG

Controller Input

It brings up this panel with a button that allows the player to close this panel and return to the main menu. But when this panel is activated the back button isn’t selected because the games already been started and the FirstSelected doesn’t apply. So there has to be a way to know what the event system is looking at right? There is. It’s called currentSelectedGameObject. So when pressing the instructions button we should make the panel activate and set the current selected to the back button?

Instructions Panel with back.JPG

Selected Back Button

But even within this menu, I could still use the controller to change the selected button to the other existing buttons in the main menu and play the game or quit even while this panel was activated. Like I mentioned before, if we select Visualize on the button it shows where they can navigate to.

Instructions Navigate.JPG

Back Navigation

The back button could still navigate to the other activated buttons. To fix it, I figured if they weren’t activated they couldn’t be navigated to. Turns out, I was right.

Transmutation Main Menu UIController.JPG

The only other thing that was different and new was using a newer version of Unity where Application.LoadLevel(value or string) had been made obsolete. It still works, but in the next version of unity (from my understanding) it won’t. So why not get into the habit of using the new version now. The new way requires the script to have access to using.UnityEngine.SceneManagement. Then instead use SceneManager.LoadScene(Value or String).

The exact same process was used when I was creating the game over menu that get’s activated by the elevator. Except if they win, it shows a happy face – If every player doesn’t survive, it shows an unhappy face.

Until next time –



Leave a comment

Posted by on August 3, 2016 in C#, Game Dev, Games


Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: