Getting into mobile development with Unity
Now, with all the background set and our course laid out, let's get started by introducing mobile development with Unity. More advanced readers who have developed Unity games on Android or iOS may want to skip ahead to Chapter 2, Mapping the Player's Location.
This installation guide is intended to be cross-platform compatible and should work on Windows, Linux, or Mac. For the sake of brevity, only screenshots for the Windows platform will be shown.
Downloading and installing Unity
Even if you have installed Unity before, but have not done mobile development, make sure that you follow this section closely. There are a couple of important steps you would not want to miss.
Perform the following steps to install Unity:
- Open any browser and go to https://unity3d.com/.
- Browse through the site and download the Unity installer for the latest stable release. If you have never downloaded Unity before, you will need to create a new account.
- Run the Unity installer, click on Next to accept the license agreement and click on Next again.
- On the architecture dialog, shown in the following screenshot, make sure that you select 64 bit:
- On the select components dialog, make sure that you choose your preferred mobile platform, Android or iOS. Many users will just select all features and install. However, it is better to be selective and install only what you need. Installing all Unity features will require about 14 GB of space, and this can quickly add up if you have installed more than one version.
In the following example screenshot, we have selected both Android and iOS. Ensure that you only select the platform you need:
Choose only the components you need
- Select the default installation path for Unity and then click on Next to install.
Even with the limited number of components, the installation will still take several minutes, so grab a coffee and wait until it completes.
Setting up for Android development
If you are using an Android device to test the game, use this section to get ready. Developers who already have experience with Android can briefly review this section or jump ahead to the Getting Started with Unity section in this chapter.
Tip
Always install the same architecture version, 64 or 32 bit.
Installing the Android SDK
Follow the subsequent steps to install the Android SDK on your development computer. Even if you already have the SDK installed, please review these steps to ensure that you have the right path and components set:
- If you have not already done so, download and install the Java Development Kit (JDK) from http://www.oracle.com/technetwork/java/javase/downloads/index.html.
Note
Always note where you install a development kit like the JDK or SDK.
- Download the latest version of Android Studio from https://developer.android.com/studio/index.html.
- After Android Studio has finished downloading, follow the instructions on https://developer.android.com/studio/index.html to start installation.
- As you install Android Studio, make sure that you also install the Android SDK, as follows:
Install the Android SDK component
- For the installation location, change the path to something that is easy for you to remember and locate. In the example screenshot,
Android/AndroidStudio
andAndroid/AndroidSDK
are used:Select an installation location that will be easy to find later on
- After the installation completes, open Android Studio. Open the Android SDK Manager by selecting menu item Tools | Android | AndroidSDK. In the following example screenshot, only Android 5, API Level 21 is selected because it matches the device:
Set the Android SDK location and select API level that matches your device
- On the Android SDK panel, set the location path to the same as you used in step 5. Then, select to install Android API level that matches your Android device and click on Apply. Locate the Android version of your phone from Settings | About phone | Android version. This API installation may take several minutes, so this will be a good time for another coffee or the beverage of choice.
- After the API installation completes, close Android Studio.
Connecting to your Android device
For best results when following the examples in this book, you will need to connect a physical device to your computer for testing. It is possible to emulate a GPS and camera in an Android emulator, but that is beyond the scope of this book. Follow these steps to get your device connected:
- Install the driver for your Android device by following this guide: https://developer.android.com/studio/run/oem-usb.html#InstallingDriver.
- Enable USB debugging on your Android device:
- On Android 4.2 and higher: The Developer options screen is hidden by default. To make it visible, go to Settings | About phone and tap on Build number seven times. After the seventh tap, you will see a message informing you that the developer options are enabled. Return to the previous screen and select Developer options at the bottom to turn on USB debugging.
- On older versions of Android, go to Settings | Applications | Development to turn on USB debugging.
- Connect your device to the computer. On the device you will be prompted to allow USB debugging. Choose Ok and wait for a few seconds to make sure that the driver connects.
- Open a command or console window on your computer and navigate to the
Android/AndroidSDK
folder where we installed the Android SDK to above. - Run the following command-line commands:
cd platform-tools adb devices
- Your device should show up in the list. If for some reason you do not see your device in the list, consult Chapter 10, Troubleshooting. The following console window shows the commands run and sample output:
That completes the bulk of setting up an Android device. We still have a couple more settings to make in Unity, but we will cover that in the next section on project setup.
Setting up for iOS development
In order to keep the content of this book focused and the development platform independent, we will not provide a step-by-step guide here. However, there is an excellent guide for iOS setup on the Unity site at https://unity3d.com/learn/tutorials/topics/mobile-touch/building-your-unity-game-ios-device-testing.
After you complete your iOS setup, return to the book, and we will begin building the example game project.