Unity Mobile Game Scripts: Joystick, Swipe, Safe Area, Touch Buttons

Build Unity mobile controls with free C# scripts for virtual joysticks, touch buttons, swipe gestures, pinch zoom, gyroscope camera, and safe areas.

Mobile controls should be decided by the game loop, not by whatever input script is easiest to paste. A one-tap hyper-casual game, a dual-stick shooter, an RTS map, and an idle game need different touch surfaces.

Pick One Main Input Pattern

Mobile Input Picker

Game TypeBest ScriptNote
Top-down movementTouch JoystickTouch Joystick gives a Vector2 direction to movement code.
Jump or attack buttonsTouch ButtonTouch Button handles press and release events for UI buttons.
Lane runnerSwipe Input ControllerSwipe Input Controller is good for left/right/up/down gestures.
Tap timing gameTap Input HandlerTap Input Handler supports tap, double tap, and long press style events.
Map or camera zoomPinch-to-Zoom CameraPinch-to-Zoom Camera handles two-finger zoom for camera control.
Device tiltGyroscope Camera ControllerGyroscope Camera Controller adds motion-based camera input.
Notched devicesMobile Safe Area HandlerMobile Safe Area Handler keeps UI inside the safe screen area.

Setup Order

  1. Create a Canvas and EventSystem before adding touch UI scripts.
  2. Add Mobile Safe Area Handler to the root UI panel.
  3. Add Touch Joystick or Touch Button depending on your control scheme.
  4. Route input into gameplay scripts through a small method or property, not by scattering UI references everywhere.
  5. Test in the Unity editor with mouse fallback, then test on a real phone before tuning sizes.

Common Mobile Mistakes

  • Too many gestures: Do not mix joystick, swipe, pinch, and tap unless each has a clear job.
  • Unsafe UI: Always account for notches, home bars, and rounded corners.
  • Tiny hit targets: Buttons that feel fine in the editor can be painful on a phone.
  • Desktop-only testing: Touch latency, thumb reach, and screen density need device testing.

When to Use the Hyper-Casual Kit

Use the Hyper-Casual Starter Kit if your game is one-tap, lane-based, stack-based, or score-driven. Use Mobile Controls Kit if your game needs a general-purpose mobile input layer.

For the broader script library, read Free Unity C# Scripts and Game Systems.

Reviewed resource

Built by Scripts For Unity

Scripts For Unity is maintained as a practical Unity scripting library by Framed Arc. The focus is copyable C# code, Inspector-friendly setup, and complete small systems that solo developers can adapt without importing a large framework.

Sources