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.cs
to your Unity project. -
Create a
Canvas
with itsRenderMode
toScreen Space - Overlay
-
The component
Canvas Scaler
'sUI Scale Mode
toScale With Screen Size
-
Add
TouchSimulator
to 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 └ Secondary
Add
Image
component to those empty gameObjects, so you can see their position. -
In
TouchSimulator
, assign Touch toTouch
field, Primary toPinch Primary
, and Secondary toPinch Secondary
. -
Subscribe to any of
TouchSimulator
's delegates:OnTapInput
OnTapSecondInput
OnDeltaInput
OnPositionInput
OnPinchInput
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/