Simulate multi-touch using mouse in Unity Editor. TouchSimulator allows mouse left click and right click to send Vector2 data needed to simulate a pinch input in a smarthphone screen.
This script is using Unity's InputSystem package.
-
Import
TouchSimulator.csto your Unity project. -
Create a
Canvaswith itsRenderModetoScreen Space - Overlay -
The component
Canvas Scaler'sUI Scale ModetoScale With Screen Size -
Add
TouchSimulatorto the canvas. -
As the child of the canvas, create an empty gameObject, and name it "Touch". As the children of Touch, make two empty gameObjects, and name them "Primary" and "Secondary".
Canvas └ Touch └ Primary └ SecondaryAdd
Imagecomponent to those empty gameObjects, so you can see their position. -
In
TouchSimulator, assign Touch toTouchfield, Primary toPinch Primary, and Secondary toPinch Secondary. -
Subscribe to any of
TouchSimulator's delegates:OnTapInputOnTapSecondInputOnDeltaInputOnPositionInputOnPinchInput
For more reference, check the example CameraController.cs which is used to control the camera movement in 2D game.
For more reference on how to actually implement pinch input in Unity, check this article: https://www.arcaneshift.com/blog/2023/06/19/pinch-and-scroll-with-unitys-new-input-system/
