Introduction and setting-up the project

Checked with version: 5.3

-

Difficulty: Beginner

Introduction

In this assignment we will be making a Tic-Tac-Toe game (also known as Noughts and Crosses) using nothing more than the built in Unity UI and two basic scripts.

description

The approach to creating the game in this lesson should show two important things.

The first is the versatility of the Unity UI toolset. Unity’s UI toolset is very powerful and can be used to accomplish many tasks in any given project. Many of these tasks may not seem to be UI related at first but the UI toolset might turn our to be the good and unexpected solution. In this project, we would like to show how, without the use of custom graphics, sprite sheets or complex interactions, we can make this game completely "out of the box" using Unity’s UI and two simple scripts.

In addition to this, we want to walk through a project by breaking it down into manageable pieces; approaching and solving one problem at a time. We will be following the steps of designing and prototyping that one could take during any game project rather than jumping straight to the finished product and explaining only how to assemble a completed game from pre-made parts. These design and prototyping steps will include refactoring code and adjusting the scope of the project as we work through this lesson.

Rather than simply showing the final, complete project, we hope that this approach will help us understand not only the underlying reason for the choices made in this project, but help understand the many small steps taken in making a game.

It is easy to be intimidated by the scope of even a small project. "Where do I start?" is a common question, followed quickly by "What now?". After doing this project, we hope that everyone will be able to start tackling larger projects by breaking them down into smaller, more manageable pieces.

Scope of the Game

The game play will be simple.

There will be a simple square game board divided into nine tiles or grid spaces. When the player clicks on one of the grid spaces, it will be assigned either an "X" or an "O". The game is over when one player claims 3 grid spaces in a row or there are no moves left. The game will have a small amount of polish to make it complete. At the start of the game, the board will not be active until the first player has chosen whether they are to play "X" or "O". A panel will indicate whose turn it is. When the game is over, a banner will display the winner or announce a draw if no one wins. A restart button will be displayed when the game is over, returning the game to the starting state when clicked.

The game will need a few basic elements.

  • A background providing a backdrop for the the entire game.
  • An element that will be our game board.
  • An element, or set of elements, that breaks the game board up into nine areas in an even grid.
  • Nine tiles that can be assigned either an "X" or and "O", but once assigned these values will persist and not be changeable by the players - either the current player or the opponent.
  • Logic to change sides when a player takes their turn.
  • Logic to check for a "Win" condition, allowing for draws where no one wins.
  • A panel that displays who is the winner when the game is over.

For polish, towards the end of the project, we could have some other, helpful elements.

  • A way to choose the starting player's side, "X" or "O".
  • An indicator of whose turn it is.
  • A restart button.
  • Very basic instructions.

Lastly, as part of this exercize, we are going to be using nothing more than the elements provided by Unity’s built in UI toolset.

Setting up the Project

Start by opening Unity and creating a new 2D project.

  • Name the project "TicTacToe" (or any other name as preferred).
  • Choose a Location so save the Project.
  • Select "2D" to set the default Project Type to 2D.
  • Click the "Create project" button to create the project.

description

For more information on Project Type and the difference between a 2D and a 3D project, please see the details on 2D and 3D projects in the Unity Manual.

Once the project has opened in the Unity Editor,

  • Create a folder called "Scenes" in the Project Window.
  • Save the default scene in the Scenes folder as "Main".

description

For more information on starting a new project, creating folders or saving scenes, please start with the getting started page in the Unity Manual and please see the lessons linked below.

In the next lesson we will be creating the iconic Tic-Tac-Toe board.

Related tutorials