top of page
Search

LAB homework-3

  • mohamedabdulgafoor
  • Oct 8, 2020
  • 3 min read

Updated: Nov 2, 2020

LAB E: Deploy Mobile Application

LAB F: Implement Mobile Application

In this lab we are going to deploy and implement a mobile application of a roll-a-ball. If you don't know how to implement a roll-a-ball in a Windows environment, please go through LAB homework-2.


Go to Unity Hub > Installs > Add Modules. Make sure to tick the "Android Build Support". Now open the roll-a-ball game, go to Edit > Preferences > External Tools. Make sure the Andriod SDK, JDK, NDK are ticked. The screenshots of the procedures as follow;

Then go to File > Build Settings > Android > Switch Platform

Wait for sometime to import required libraries. If everything is completed, you should be able to find a tiny Unity icon next to the Android icon.

Now go to Player Settings. Then Project Settings will open. Go to Player and choose Android icon. And under the Resolution and Presentation, choose Landscape Right as a default orientation.

And under the Other Settings, if you have Vulkan graphics, make sure to remove it as it may course problems with the AR technology. To remove, simply click the minus sign. Luckily I don't have this problem :). Make sure the Minimum API Level, Target API Level are correct.

If you plan to publish the game in the future, you need to create a unique key. This can be done under the Publishing Settings. Now go to Publishing Settings > Keystore Manager > Create New > In Dedicated Location. You have to simply fill up the necessary information.


Okay time to build the mobile version now. ;)

I use a Honor mobile to develop this. Let us enable USB Debugging in Honor.

Go to Settings > About Phone > Build Number (TAB for 7 times). Then you will see a message saying you are a developer or if you already done this, it will say you are already a developer. Now again Settings > System & Updates > Developer Options and enable USB debugging. Now connect your smart phone and Build and Run.


Android SDK is missing required platform API

I got the above message when I try to build and run. A simple Update Android SDK did not work in my case and other methods as well. So I found a solution in a YouTube page. That helps me to fix the issue.


If Build and Run successfully completed, you will see the roll-a-ball game appear in your android device. The following figure shows the game in my android device.

So how do we utilize the existing sensors in our mobile to interact with the game? We can use for example accelerometer, gyroscope or light-sensors.

Now let us use mobile input interaction. First of all, remove the Player Input from the inspector panel that we have created for the Windows (otherwise we can not have two Player Input). We will create a separate Player Input for the mobile. Create a folder called MobileInput in assets. In the inspector panel click add components. Then Player Input > click Create Actions. Let's save it as "mobileInPutInteraction". From the Player Input under the inspector panel, choose Actions as mobileInPutInteraction. The figure bellow shows the screenshot.










Sensor support

Unity provide a wide range of sensors. Sensors can be used to measure the acceleration of the device, orientation, humidity etc. If you want to enable/disable a gyroscopic sensor, you can simply do;

enable

InputSystem.EnableDevice(Gyroscope.current);


disable

InputSystem.DisableDevice(Gyroscope.current);



Accelerometer.










In this lab let us use a accelerometer to control the roll-a-ball. Remember instead of rb.AddForce(movement * speed), we will use rb.AddForce(accelerometer_values).


Now let us change the Main Camera to a top view and change few parameters.





Also I create another UI to print the sensor values of acceleration. The process is same as before. Go to Hierarchy > UI > Text-TextMeshPro.


We must do a modification to the PlayerController.cs script. Let us create a boolean (isMobileBuild) variable and enable the Accelerometer sensor. The following modification in the Start() function will do the job.










"An accelerometer let's you measure the acceleration of a device, and can be useful to control content by moving a device around. Note that the accelerometer will report the acceleration measured on a device both due to moving the device around, and due gravity pulling the device down" (ref 3). The following code snippet get the magnitude and direction of acceleration from the device and store the value in "a".

Also note that, I put Main Camera, PickUpYellowParents, PickUpGreenParents, Walls, Directional Light under the parent GameObject Ground.


Finally I create .apk file using Build. I transfer this .apk file into my android device and install it. :)

The following video shows how the roll-a-ball game looks like in an Android device. Create your own application, install it in your Android device and play it.

This is my first experience in mobile application and this is indeed cool :)

References:


 
 
 

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2020 by var4all. Proudly created with Wix.com

bottom of page