Testing the game

Even though we now are on the Android platform for this project, everything works perfectly. We do not have to change anything for the game to work while running in the editor. Let's build the game and try it on a mobile device to see whether it's still the same.

We'll see how to configure Bundle Identifier and then explore two different ways to build and run our game on an Android device.

Bundle Identifier

Before we start building the game, we need to define Bundle Identifier. Bundle Identifier is a unique ID for all Android apps. When your game is uploaded to the Google Play Store, it is identified and published using this unique ID. Perform the following steps to define Bundle Identifier:

  1. Navigate to Edit | Project Settings | Player.
  2. The Player Settings menu is now displayed in the Inspector panel.
  3. Click on the Other Settings submenu to display them.
  4. Under the Identification group, you'll see the Bundle Identifier field.
  5. Enter com.Aze.LearnNGUI in the Bundle Identifier field.

Tip

You can put your company name instead of Aze.

Once Bundle Identifier has been set up, we can move on to building the package.

Building the package

We have two different ways of building a package with Unity: a manual build and a build and run option. We'll explain and try both now.

Manual build

In the File | Build Settings window, click on the Build button. Leave the default name for the .apk package, select the current project's root folder (default location), and then click on Save:

Manual build

Unity will build the Android package. Once it's finished, connect your Android device to your computer with an USB cable, and copy the .apk file on it—in your folder of choice. Use any Android file explorer (File Expert for example) to browse and install it. It will then be added to your home screen and you will be able to launch it like any other Android app.

Now that we've seen the manual build, let's talk about the Build And Run feature.

Build and run

We've seen that we can build an .apk package file on the computer's hard disk, copy it to your Android device, install it manually, and launch it.

With Unity, in the Build Settings window, a Build And Run option exists. This will build the package and install and launch it automatically. A good time-saver!

For the Build and Run option to work, you must enable USB debugging on your Android device.

If you have an Android version lower than 4.2, you should see Developer Options in the system parameters. From Android 4.2, you must request to be shown the following elements:

  1. Access the system parameters.
  2. Go to the About submenu.

    Note

    Depending on the device's manufacturer, the About submenu can be under More | General, or Software Information | More.

  3. Scroll to Build Number.
  4. Tap Build Number seven times.
  5. A notification saying You are now a developer appears.
  6. Go back to the system settings.
  7. Enter Developer Options.
  8. Enable the USB Debugging option.

Now that the USB debugging feature is enabled, you can either navigate to File | Build Settings and click on the Build And Run button, or simply hit Ctrl + B to build and run the game on your device!

Testing

Now, run the Learning NGUI app on your mobile device. If you've used the build and run option, it should launch automatically.

You can see that the menu works well, and if you rotate your device, it auto-adjusts the UI to fit:

Testing

Even though we will lock the game in landscape orientation, it's good to know that by enabling both content width and height's Fit options make sure that the UI scales up or down to fit the current screen's size, even when it's flipped during runtime.

Click on the Options button. You'll see that all the interface works correctly; we do not have any issues here.

Return to the main menu and click on the Play button. You can easily drag the power sources. That's great.

Unfortunately, the character doesn't move when the player clicks on the ground. Also, it is impossible to display the power source's elemental switch UI since we do not have a right-click button on mobile devices.

Finally, hitting Android's back button (same as the Esc key on computers) directly exits the game instead of simply pausing it.

Ok, those are the three main issues. Let's start working on them!

Tip

Using dynamic lights on mobile platforms with Unity greatly reduces performance. If you have trouble running the game smoothly on your device, disabling those attached to the player and power sources might help.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.151.164