Book Image

Unity 2020 Mobile Game Development - Second Edition

By : John P. Doran
Book Image

Unity 2020 Mobile Game Development - Second Edition

By: John P. Doran

Overview of this book

Unity 2020 brings a lot of new features that can be harnessed for building powerful games for popular mobile platforms. This updated second edition delves into Unity development, covering the new features of Unity, modern development practices, and augmented reality (AR) for creating an immersive mobile experience. The book takes a step-by-step approach to building an endless runner game using Unity to help you learn the concepts of mobile game development. This new edition also covers AR features and explains how to implement them using ARCore and ARKit with Unity. The book explores the new mobile notification package and helps you add notifications for your games. You’ll learn how to add touch gestures and design UI elements that can be used in both landscape and portrait modes at different resolutions. The book then covers the best ways to monetize your games using Unity Ads and in-app purchases before you learn how to integrate your game with various social networks. Next, using Unity’s analytics tools, you’ll enhance your game by gaining insights into how players like and use your game. Finally, you’ll take your games into the real world by implementing AR capabilities and publishing them on both Android and iOS app stores. By the end of this book, you will have learned Unity tools and techniques and be able to use them to build robust cross-platform mobile games.
Table of Contents (14 chapters)

Exporting a project for Android

Now that we have all of the setup done, we can open Unity with our project and export it for Android devices. In this section, we will first check whether we have Android Build Support installed, and then we will update the build and player settings to export our project. So, let's get started.

Installing Android Build Support for Unity

First of all, if you haven't done so already, you'll need to have selected to add Android Build Support as an option when you are installing Unity. If you have installed it, you can skip this section. If you did not install it when doing the initial installation, that is what we will cover in the following steps:

  1. Close the Unity Editor and then open up the Unity Hub and select the Installs section.
  2. From there, click on the three dots to the right of your current version of Unity and select the Add Modules option:
  1. Check the Android Build Support option, which should also check the Android SDK and NDK Tools and OpenJDK options. Afterward, click on the NEXT button:
  1. You'll be brought to a license terms page. Read it over and if you agree to it, check the agreement box and click on the DONE button:
  1. Wait for it to finish installing. Once finished, you should see the Android logo at the bottom of your install:

This means that Android Build Support has now been added to our version of Unity and we can build projects there. Next, we will see how to actually build the project for Android and the settings required to do so.

Updating build and player settings for Android projects

Now that we have Android support, let's open up our project again and change the platform we are developing for:

  1. At this point, we will dive into Unity and move into our Build Settings menu once again by going to File | Build Settings.
  1. Click on the Android option from the Platform list and then click on the Switch Platform button to make the change:

Note that this will make Unity reimport all of the assets in our game, so this may be time-consuming when you start to build larger projects. Once completed, you should notice that the Unity logo is now next to the Android option, signifying that's the platform to be built for:

  1. Now, in order to be able to build our project, we must set the bundle identifier for our game, which is a string that identifies the app. It's written like a URL in reverse, for example, com.yourCompanyName.yourGameName. To modify this, we'll need to open up the Player Settings menu, which we can get to by clicking on the Player Settings... button in the bottom-left part of the Build Settings menu or by going into Edit | Project Settings | Player. You'll note that the menu shows up as a new window:

Now that we're in Android mode (note the text on the title bar of the Unity Editor), we can change these properties:

  1. We'll discuss more of these in a later chapter, but for now, scroll down until you get to the Other Settings option, and from there, you'll see the Package Name property. We will change this to something else; for example, I used com.JohnPDoran.MobileDev. There's also a Minimum API Level option; make sure that your option is set to the same version as your phone or earlier, depending on what you want to support. Note that the earlier you go, the fewer things you'll have access to, but your project will be able to support more phones:
  1. Close the Project Settings window and open up the Build Settings menu again by going to File | Build Settings. Now, we can try to build the project by clicking on the Build button, saving it in the same Export folder we created earlier. It will ask for the name you'd like the file to have. I will use MobileDev as we did previously, because instead of a .exe file, it will be creating a .apk file:

Wait a bit, and once it's finished, you should have a new .apk file located in the folder. Of course, just having the APK file doesn't do much if we can't put it on our actual phone; so, in the next section, we will enable our phone to test the game on our device.