Mobile Controls Kit
Complete touch input system for any mobile Unity game — virtual joystick, on-screen buttons, swipe gestures, pinch-to-zoom, gyroscope, and safe area handling.
6 scripts intermediate Starter kit Any mobile Unity game needing touch controls
Download mobile-controls-kit.zip 6 scripts and a README · 21 KB of C# · MIT
What is inside
- TouchJoystick.cs Virtual on-screen joystick for mobile touch input with dynamic or fixed positioning. Outputs normalized Vector2 direction suitable for character movement.
- TouchButton.cs Mobile-friendly UI button with press, release, and hold events plus visual feedback. Includes configurable cooldown and hold duration tracking for responsive touch controls.
- SwipeInputController.cs Detects touch swipes in four directions with configurable thresholds and dead zones. Fires UnityEvents for each swipe direction with speed and distance tracking.
- PinchToZoomCamera.cs Smooth pinch-to-zoom camera control for mobile devices supporting both orthographic and perspective cameras. Features configurable zoom limits and optional smoothing.
- GyroscopeCameraController.cs Rotates the camera with the device gyroscope, with smoothing, sensitivity, calibration, axis locking and a fallback for devices without a gyroscope.
- MobileSafeArea.cs Fits a UI RectTransform to the device safe area on notched phones and tablets, and updates on orientation changes, on iOS and Android.
What it does
- Virtual joystick with dynamic positioning
- Configurable on-screen action buttons
- 4-directional swipe gesture detection
- Pinch-to-zoom for orthographic and perspective cameras
- Gyroscope-based camera look
- Automatic safe area handling for notched devices
Setup, in order
- Import all scripts into your Unity project
- Create a UI Canvas and add TouchJoystick to a child Image element
- Add TouchButton components for action buttons (jump, attack, etc.)
- Attach SwipeInputController to a manager for gesture detection
- Add PinchToZoomCamera to your main camera for zoom support
- Add a full-screen panel under the Canvas, attach MobileSafeArea to it, and put the controls inside it
If something does not work
- The joystick and buttons do not respond to touch
- They use Unity UI pointer events, so the scene needs an EventSystem and the Canvas a Graphic Raycaster. Make sure no other full-screen UI image with Raycast Target on sits above the controls.
- Controls sit under the notch or home bar
- Put MobileSafeArea on a full-screen panel under the Canvas and make the controls its children. It resizes that panel to
Screen.safeArea, so anything outside the panel is not protected. - The gyroscope camera does nothing
- It checks
SystemInfo.supportsGyroscopeand stays still on devices without one, including the Editor and most tablets without motion sensors. Test on a phone. - Every input call throws InvalidOperationException in a new Unity 6 project
- The scripts read the legacy Input class, which new Unity 6 projects switch off. Set Project Settings > Player > Active Input Handling to Both and let the Editor restart. Details and the Input System alternative.
Preview
An excerpt of the kit's main types, and the Inspector fields they expose.
Inspector
Fields from the kit's preview excerpt; the full kit has more.
Handle Range 50
Dynamic Position
Swipe Threshold 50
Excerpt
C#
// TouchJoystick.cs - Virtual joystick for mobile
public class TouchJoystick : MonoBehaviour
{
[SerializeField] private float handleRange = 50f;
[SerializeField] private bool dynamicPosition = true;
public Vector2 InputDirection { get; private set; }
// Drag handle within range, returns normalized direction
// Supports dynamic repositioning on touch start
}
// SwipeInputController.cs - Swipe gesture detection
public class SwipeInputController : MonoBehaviour
{
[SerializeField] private float swipeThreshold = 50f;
public event Action<SwipeDirection> OnSwipe;
// Detects Up, Down, Left, Right swipes
// Filters taps vs swipes by distance threshold
}Related
- Hyper-Casual Starter KitEverything you need to prototype hyper-casual games in hours — one-tap input, endless runner template, stack mechanic, score tracking, and swipe controls.
- 2D Platformer Starter KitComplete 2D platformer foundation with movement, camera, advanced mechanics, health, collectibles, and transitions.
- FPS Foundation KitFirst-person shooter foundation with movement, camera, weapons, projectiles, health, and screen shake.