Skip to main content
Unity 3D Basics – Complete Beginner to Advanced Guide
CHAPTER 14 Beginner

Mobile Game Development Basics

Updated: May 16, 2026
30 min read

# CHAPTER 14

Mobile Game Development Basics

1. Introduction

The mobile gaming market is the largest sector in the video game industry. A simple hyper-casual game released on iOS or Android can reach millions of players worldwide. However, mobile devices do not have keyboards or mice; they rely entirely on multi-touch glass screens. Furthermore, a mobile phone has a fraction of the processing power of a gaming PC, requiring strict optimization. In this chapter, we will master Mobile Game Development Basics. We will learn how to read raw touch inputs, implement virtual on-screen joysticks, configure responsive UI, and prepare our project for an Android build.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Switch a Unity project's build target from PC to Android/iOS.
  • Read multi-touch screen inputs using Input.touches.
  • Implement virtual on-screen UI joysticks and buttons.
  • Optimize graphics settings for low-end mobile hardware.
  • Build an Android APK file for device testing.

3. Switching the Build Platform

By default, Unity assumes you are making a Windows/Mac PC game. To unlock mobile features, you must switch the engine's target architecture.
  1. 1. Go to File -> Build Settings.
  1. 2. Under "Platform", select Android (or iOS).
  1. 3. Click the Switch Platform button. Unity will take a few minutes to re-compress all your audio and textures into mobile-friendly formats.

4. Reading Touch Input (The Raw Way)

Instead of Input.GetKeyDown, mobile phones track multiple fingers touching the screen simultaneously using an Array called Input.touches.
csharp
12345678910111213141516
void Update()
{
    // Are there any fingers on the screen?
    if (Input.touchCount > 0)
    {
        // Get the data for the first finger that touched the screen (Index 0)
        Touch touch = Input.GetTouch(0);

        // Did the finger just tap the screen this exact frame?
        if (touch.phase == TouchPhase.Began)
        {
            Debug.Log("Screen Tapped at coordinate: " + touch.position);
            Jump();
        }
    }
}

5. On-Screen UI Joysticks

Writing raw touch math to simulate a thumbstick is incredibly tedious. Unity provides a free, pre-built package for this!
  1. 1. Open the Package Manager (Window -> Package Manager).
  1. 2. Install the Device Simulator or the Standard Assets (CrossPlatformInput) (depending on your Unity version).
  1. 3. Alternatively, search the Asset Store for "Free Mobile Joystick".
  1. 4. You simply drag the UI Joystick Prefab onto your Canvas.
  1. 5. In your C# code, instead of Input.GetAxis("Horizontal"), you change it to FixedJoystick.Horizontal. The transition takes 5 seconds and perfectly maps your PC movement code to a touch screen!

6. Mobile Optimization (Crucial Step)

A beautiful PC game will melt a phone's battery and run at 10 FPS. You must optimize:
  • Shadows: Real-time shadows are incredibly expensive on mobile. Go to Edit -> Project Settings -> Quality, and change Shadows to Hard Shadows Only, or disable them completely and use "Baked" (pre-painted) lighting.
  • Poly Count: A PC character can have 50,000 polygons. A mobile character should be kept under 10,000.
  • Post-Processing: Avoid heavy effects like Depth of Field or Ambient Occlusion on mobile.

7. Building an Android APK

To play the game on your physical Android phone:
  1. 1. Ensure your phone is plugged in via USB and "Developer Options / USB Debugging" is enabled on the device.
  1. 2. In Unity, go to Edit -> Project Settings -> Player.
  1. 3. Under the Android tab, set the Company Name and Product Name.
  1. 4. Set the Minimum API Level (e.g., Android 8.0).
  1. 5. Go to File -> Build Settings.
  1. 6. Click Build and Run. Unity will compile the C# code into a .apk file, push it through the USB cable, and instantly launch the game on your phone!

8. Visual Learning: Touch Phases

txt
123456
A single finger touch transitions through "Phases":

1. TouchPhase.Began      -> (Frame 1: Finger touches the glass)
2. TouchPhase.Moved      -> (Finger drags across the screen)
3. TouchPhase.Stationary -> (Finger rests, not moving)
4. TouchPhase.Ended      -> (Finger is lifted off the glass)

9. Best Practices

  • Device Simulator: You don't have to build an APK every time you want to test mobile UI. Unity has a built-in Device Simulator window (accessible next to the Game tab). It overlays a virtual iPhone or Samsung bezel over your game, allowing you to perfectly test UI Safe Areas (preventing UI from being hidden under the camera notch) right in the editor.

10. Common Mistakes

  • Assuming Mouse = Touch: In the Unity Editor, clicking the mouse emulates a touch, making it easy to test. However, relying on Input.GetMouseButtonDown(0) in your final mobile build can cause weird glitches on multi-touch devices. Always switch to true Input.touches logic before publishing a mobile game.

11. Mini Project: Convert to Mobile Controls

Objective: Replace PC keyboard movement with mobile UI buttons.
  1. 1. Create a Canvas with two Buttons anchored to the bottom corners. Label them "Left" and "Right".
  1. 2. Add an EventTrigger component to each button. This allows us to detect when the button is *held down*, not just clicked once.
  1. 3. Create a MobileController script:
csharp
123456789101112131415
public class MobileController : MonoBehaviour
{
    public float speed = 5f;
    private int moveDirection = 0; // -1 for left, 1 for right, 0 for stop

    void Update()
    {
        transform.Translate(moveDirection * speed * Time.deltaTime, 0, 0);
    }

    // Connect these to the UI EventTriggers (PointerDown / PointerUp)
    public void PressLeft() { moveDirection = -1; }
    public void PressRight() { moveDirection = 1; }
    public void ReleaseButton() { moveDirection = 0; }
}
  1. 4. Map the UI Event Triggers to these functions. You can now steer your character using your thumbs on the screen!

12. Practice Exercises

  1. 1. What menu option must you select to reconfigure Unity's backend from compiling .exe files to compiling .apk files?
  1. 2. If you want to run code only on the exact frame a player's finger lifts off the glass, which TouchPhase should you check for?

13. MCQs with Answers

Question 1

When developing a game for low-end mobile devices, which graphics feature is considered highly expensive and should often be heavily restricted or baked?

Question 2

How does Unity represent the data of multiple fingers touching the screen simultaneously?

14. Interview Questions

  • Q: Explain the lifecycle of a mobile touch input via the TouchPhase enum. How do Began, Moved, and Ended correlate to standard mouse clicks?
  • Q: A PC game port is running at 15 FPS on a modern smartphone. Detail three specific rendering optimizations you would perform in the Unity Editor to drastically improve performance.
  • Q: Describe the workflow for testing mobile UI responsiveness in the Unity Editor without having to build to a physical device every 5 minutes.

15. FAQs

Q: Can I build an iOS game using a Windows PC? A: No. While you can *develop* the game on Windows, Apple has a strict walled garden. To actually compile the final .ipa file to put on an iPhone or the App Store, you MUST export the project to an Apple Mac computer running Xcode.

16. Summary

In Chapter 14, we transitioned into the mobile market. We learned how to switch our build architecture to Android and use the Device Simulator to test screen resolutions. We bypassed traditional keyboards, implementing raw multi-touch tracking via the Input.touches array and utilizing virtual on-screen joysticks. Finally, we learned critical rendering optimizations required to keep our games running smoothly on battery-powered hardware, and outlined the pipeline for compiling a playable .apk.

17. Next Chapter Recommendation

Our game runs great on mobile, but on PC, we want it to look like a AAA masterpiece. Proceed to Chapter 15: Lighting, Effects, and Post Processing.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·