Category Archives: Game Development

New Unity Template Using nGUI

One thing I worked on in my spare time was creating a template to start any Unity game. One problem was that the menu system didn’t quite handle all controls that well.

Well, thanks to the new GUI system, they made handling all input a breeze. My new template can be found on my Github page. As an added bonus, I added a Google play leader board plug in! Hopefully someone else finds it useful.

Fun with Unity GUI Controls

In preparation for some serious game coding in the new year with code jams, OGAM, and hopefully more, I’m creating a template for all my Unity games. I really don’t want to deal with creating a title screen, menus, and all that jazz, so I’m preparing this now. It’s actually somewhat easy once you start reading everyone’s solutions to problems, so I’ll consolidate some of those resources here. By the way, if you want to check out the template, it’s located at https://github.com/monkeysSuck/BaseUnityProject.

Controller Input and Menus

The element you’ll probably be rushing to use to create a GUI is the standard button (GUI.Button). However, there’s a much better object to use: GUI.SelectionGrid. With this, you can consolidate input methods as well:

public const float fMaxJoystickRange = 0.8f; // Joystick range for detecting input

void Update() {
	if (Input.GetButtonUp("Up") || 
            Input.GetAxis("Vertical") < -fMaxJoystickRange)
        {
            iSelected = Mathf.Max(iSelected - 1, 0); 	
        } 
        else if (Input.GetButtonUp("Down") || 
                 Input.GetAxis("Vertical") > fMaxJoystickRange)
        {
            iSelected = Mathf.Min(iSelected + 1, 
                            arrButtonNames.Length - 1);
	} 
        else if (Input.GetButtonUp("Select") || 
                 (GUI.changed && Input.GetMouseButtonUp(0)) || 
                 Input.GetButtonUp("Select (Controller)"))
        {
            ProcessInput();
	}
}

The best part about this? It handles mouse, keyboard, and controller. All of these inputs are set via InputManager. For the mouse input, I do an additional check for GUI.changed because we want to avoid clicks outside of the GUI.

Pausing the game

Pausing the game is also quite easy. Adding a small script that gets added/removed when a button is pushed. In this script, when the script is initialized, store the old Time.timeSpan value and set Time.timeSpan to 0. Then, in the script’s OnDestroy method, reset Time.timeSpan to the stored value.

HOGJam #2

Over December 12, 2013, Chris Lorenz and I participated in the second HOGJam here in Seattle, WA. It was a 24-hour game jam, but due to other obligations, we finished this in 6. After a little polish after the fact, here’s the game we made!

HOGJam #2 – Free Chicken, Weird Chicken

Windows | Mac | Linux

Chicken Controls:

Jump: Controller 2 Button 0 or P (can multi jump)
Lay egg: Controller 2 Button 1 or O

Weird Controls:

Jump: Controller 1 Button 0 or X