Unity Touch & Mobile Scripts
12 free C# scripts 6 beginner6 intermediate Unity 2022.3+ MIT licensed
Mobile games need input and layout work that desktop projects never see. This category has the input side, with swipe, tap and long-press detection, a virtual joystick, touch buttons, pinch-to-zoom and gyroscope camera control, and the layout side, with a safe-area handler for notched phones and a UI scaler for different aspect ratios.
It also includes the core loops of common hyper-casual and idle games: an endless runner controller with lanes, a tap-to-stack mechanic, a score manager with combos and saved high scores, and an idle income generator with offline earnings.
Start with Swipe Input Controller
Detects touch swipes in four directions with configurable thresholds and dead zones. Fires UnityEvents for each swipe direction with speed and distance tracking.
SwipeInputController.cs · 9 Inspector fields · beginner
Open Swipe Input ControllerAll 12 touch & mobile scripts
- Swipe Input Controller Detects touch swipes in four directions with configurable thresholds and dead zones. Fires UnityEvents for each swipe direction with speed and distance tracking.
- Tap Input Handler Handles single tap, double tap, and long press gestures with configurable timing. Provides tap position in both screen and world space coordinates.
- Score Manager Complete score management system with high score persistence, combo multipliers with decay, and score change events. Uses singleton pattern for easy global access.
- Touch Button Mobile-friendly UI button with press, release, and hold events plus visual feedback. Includes configurable cooldown and hold duration tracking for responsive touch controls.
- Stack Mechanic Tap-to-place stacking mechanic: stop the moving block over the last one. Trims the overhang, detects perfect placements and tracks stack height.
- Mobile Safe Area Handler Fits a UI RectTransform to the device safe area on notched phones and tablets, and updates on orientation changes, on iOS and Android.
- Touch Joystick Virtual on-screen joystick for mobile touch input with dynamic or fixed positioning. Outputs normalized Vector2 direction suitable for character movement.
- Endless Runner Controller Complete endless runner character controller with auto-forward movement, lane switching, jump and slide mechanics. Speed increases over time with death and restart handling.
- Pinch-to-Zoom Camera Smooth pinch-to-zoom camera control for mobile devices supporting both orthographic and perspective cameras. Features configurable zoom limits and optional smoothing.
- Idle Income Generator Passive income system for idle/clicker games with offline earnings calculation, upgrade scaling, and prestige mechanics. Handles large numbers with K/M/B/T formatting.
- Gyroscope Camera Controller Rotates the camera with the device gyroscope, with smoothing, sensitivity, calibration, axis locking and a fallback for devices without a gyroscope.
- Mobile Responsive UI Scaler Adjusts UI scale to the device's aspect ratio, DPI and orientation alongside CanvasScaler, so fonts stay readable and layouts hold on every phone.
What these scripts need
Read from each script's source, so this list stays in step with the code.
Reads the legacy Input Manager (UnityEngine.Input). If Project Settings > Player > Active Input Handling is set to Input System Package only, Unity throws an InvalidOperationException; set it to Both.
6 of 12: Swipe Input Controller, Tap Input Handler, Stack Mechanic, Endless Runner Controller, Pinch-to-Zoom Camera, Gyroscope Camera Controller
Uses uGUI (UnityEngine.UI): needs a Canvas in the scene.
3 of 12: Touch Button, Touch Joystick, Mobile Responsive UI Scaler
Uses the UI event system: the scene needs an EventSystem object.
2 of 12: Touch Button, Touch Joystick
Calls DontDestroyOnLoad, so the object survives scene loads. Place it once, in your first scene.
Applies to: Score Manager
Requires RectTransform on the same GameObject.
Applies to: Mobile Safe Area Handler
Requires CharacterController on the same GameObject.
Applies to: Endless Runner Controller
Requires CanvasScaler on the same GameObject.
Applies to: Mobile Responsive UI Scaler
Kits that build on them
- Hyper-Casual Starter Kit Everything you need to prototype hyper-casual games in hours — one-tap input, endless runner template, stack mechanic, score tracking, and swipe controls.
- 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.
- Idle Game System Core systems for idle/incremental games — passive income generation, offline earnings, upgrade progression, number formatting, and responsive mobile UI.
Guides that use them
- Free Unity C# Scripts and Game Systems: 55 Copy-Paste Tools for Indie Games A catalog of 55 free Unity C# scripts and 13 game systems: movement, camera, health, save/load, UI, AI, mobile controls, inventory and dialogue.
- Unity Touch Input Best Practices: Phases, Multi-Touch, Dead Zones and Haptics How touch input works in Unity: phases, finger IDs, multi-touch, dead zones, haptics and EnhancedTouch, plus the mistakes that make mobile controls feel bad.
- How to Add Touch Controls to Your Unity Mobile Game Complete guide to implementing mobile touch controls in Unity. Covers virtual joystick, on-screen buttons, swipe gestures, pinch to zoom, and safe area scaling.