Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Augmented Reality Game Development

You're reading from   Augmented Reality Game Development Create your own augmented reality games from scratch with Unity 5

Arrow left icon
Product type Paperback
Published in Jan 2017
Publisher Packt
ISBN-13 9781787122888
Length 334 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Micheal Lanham Micheal Lanham
Author Profile Icon Micheal Lanham
Micheal Lanham
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started FREE CHAPTER 2. Mapping the Player's Location 3. Making the Avatar 4. Spawning the Catch 5. Catching the Prey in AR 6. Storing the Catch 7. Creating the AR World 8. Interacting with an AR World 9. Finishing the Game 10. Troubleshooting

Getting started with Unity

Unity is a great platform to start learning game development or even shipping a commercial game. It is the choice of game engine for many of the popular games in the Android or iOS app stores. So, what makes Unity such a great platform to develop games on? The following is a short list of things that make Unity such a compelling platform to develop games on:

  • It is free to get started: There is a ton of free assets or code you can use to build games. We will look at a number of free assets in this book.
  • Incredibly easy to use: You could likely build a complete game in Unity without writing even one line of code. Fortunately, you will learn some scripting and how to write code in this book.
  • Entirely cross platform: With Unity, you can develop on or for any environment that suits you. Of course, certain platforms, such as mobile, still have limitations and we will cover that as well.
  • Outstanding community: Unity has a hardcore base of developers who are eager to share experiences and help others. We will be sure to showcase many of the great community resources.
  • Asset Store: The Unity Asset Store can be an invaluable tool to build your first game or even your seventh commercial title. We will show you the deals and what to avoid.

Creating the game project

Let's get started by creating our sample game project Foody GO; we will also take this opportunity to build and deploy this starting project to your mobile device:

  1. Launch Unity and start a new project named FoodyGO. Make sure that 3D is enabled and disable Unity analytics. Of course, you will want to save your project in an easy-to-find folder, such as Games, just as shown in the following sample screenshot:

    Creating the game project

  2. Click on the Create project button and wait for Unity to open.
  3. In the Hierarchy window (top-left corner), you will see a scene named Untitled. Beneath that, there will be the Main Camera and Directional Light attached. Here is the screenshot of what you will see:

    Creating the game project

  4. First thing you will want to do is rename the scene and save it. So, go to File | Save Scene As...
  5. A save dialog will open, allowing you to choose where to save the scene. Just choose the default Assets folder and name your scene Splash. Then, click on Save.
  6. The title of the scene should now read Splash. Notice that there is also a new Splash scene object in the project Assets folder.
  7. Now let's adjust the Unity editor layout to match how our mobile game will run. From the menu, select Window | Layouts | Tall. Then, undock the Game tab from the main window by selecting and clicking the mouse while dragging the tab over. Then, resize the window so both the scene and game windows are roughly of the same width.
  8. Save the layout by opening the menu to Window | Layouts | Save Layout. Name your layout Tall_SidebySide and click on Save. This will allow you to quickly return to this layout later.
  9. Select the Main Camera by double-clicking on it, in either the Hierarchy window or Scene window. Notice how the Scene window will focus on the Main Camera object, and the Inspector window will display all the properties. This is what the Unity editor window should look like now:

    Creating the game project

    Editor layout for mobile development

  10. Before we go further, let's take a look at each of the main windows we will be working with in Unity:
    • Scene window: This window will allow you to view and interact with the game objects in the scene.
    • Game window: This is the players' view of the scene rendered by the main camera.
    • Hierarchy window: This shows a tree view of the game objects in the scene or scenes. In most cases, you will select or add items to the scene in this window.
    • Project window: It provides a view of and a quick way to access the assets in your project. Not much is in our project now, but we will quickly add some new assets in the coming chapters.
    • Inspector window: This view allows you to inspect and alter settings on game objects.
  11. Click on the Play button located at the top middle of Unity editor. The game will start playing, but nothing will happen because we only have a camera and a light. So let's add a simple Splash screen.
  12. In the Hierarchy window, select the scene. From the menu, select Game Object | UI | Panel to add a Canvas and Panel to the scene.
  13. Double-click on the Panel object in the Hierarchy window. This will focus the Scene window on the panel. In the Scene window, switch the view to 2D by clicking the button at the top of the window. This is what you should see now:

    Creating the game project

    Editor window with UI focused on in Scene window

  14. The panel in the scene window is a 2D UI element that allows us to render text or other content to the player. By default, the panel centers itself to the main view of the camera when it is added to the scene. This is why we see the semitransparent panel cover the entire Game window. Since we don't want a transparent background to the splash screen, let's change the color.
  15. Select the Panel in the Hierarchy window. Then, click on the white box beside the Color property in the Inspector window to open the Color settings. You will see the following dialog:

    Creating the game project

  16. Enter FFFFFFFF in the Hex Color field and then close the dialog. Notice how the background of the Game window is now opaque white.
  17. From the menu, select Game Object | UI | Text. In the Inspector window, set the properties of the Text to match the screen extract, as follows:

    Creating the game project

  18. Run the game by clicking on the Play button. Not much happens, but we now have a splash screen for our game. Don't worry, later in the book, we will add some pizazz to this screen. For now though, let's get this game deployed to your device.

Building and deploying the game

Now that we have the foundations of our game and a simple splash screen let's deploy it to your device. Nothing confirms your progress as a game developer other than seeing your game run outside the Unity editor. Follow the section that is specific to your device to complete the build and deployment.

Building and deploying to Android

As long as you have followed the steps for installation in the previous sections of this chapter, deploying your game to Android should be simple. If you do encounter any deployment issues, refer to Chapter 10, Troubleshooting. Follow the next steps to build and deploy to your Android device:

  1. From the menu, select Edit | Preferences. This will open the preferences dialog.
  2. Select the External Tools tab. Change or set the location of your Android SDK Path and Java JDK Path to the installation paths we made a note of when installing. Close the dialog when you are finished. The subsequent sample screenshot shows where you need to enter those paths:

    Building and deploying to Android

  3. Select Edit | Project Settings | Player from the menu. Select the Android Settings tab and then click on Other Settings at the bottom of the panel. Set the Bundle Identifier to com.packt.FoodyGO as shown in the following screenshot:

    Building and deploying to Android

  4. Make sure that your Android device is connected by the USB. Refer to the Connecting to your Android Device section earlier in this chapter if you are unsure.
  5. Open the Build Settings by selecting from the menu File | Build Settings. On the Build Settings dialog, click on the Add Open Scenes button to add the Splash scene. Ensure that you select the Android build from the list of build types. When you are all set and ready, click on the Build and Run button. This is how the Build Settings dialog should look like:

    Building and deploying to Android

  6. A file save dialog will open the project's root folder. Create a folder called Build while you still have the dialog box opened. Open the new Build folder and save your build as com.packt.FoodyGO. The name should match the name we used for the build identifier earlier. Then, click on Save to start the build.
  7. Since this is the first build of the project, Unity will reimport all the project assets and other modules, which may take a few minutes. Subsequent builds should take less time, but if you change platform outputs, everything will need to be reimported.
  8. After the build completes, open your device. You will likely see the Unity screen loading and then the splash screen. Congratulations, you have deployed the game to your device.

Building and deploying to iOS

Assuming you followed the previous section, Setting up for iOS development, you should be able to already build and deploy the game to your device. Just follow the build and deployment steps again in that page to deploy the game to your device. Download the sample project for the chapter and deploy that to your iOS device.

You have been reading a chapter from
Augmented Reality Game Development
Published in: Jan 2017
Publisher: Packt
ISBN-13: 9781787122888
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image