Input.GetMouseButtonDown() translates automatically to Mobile Platforms?
Say I wrote a mouse-only game for PC, using Input.GetMouseButtonDown(0) and functions like those. Will these functions work also on Mobile touchscreen devices like Android or iOS, and translate automatically to the finger taps?
In other words, do I need to edit my project or will Unity do these translations automatically for me?
The reason I ask is when I run the Android emulator with my project, as soon as I trigger an event which is mouse-press, the emulator crashes.
Thank you!
Yes, Unity can use most PC input commands on a touchscreen. It's a feature Unity3D added to those commands. Search "unity onmousedown touchscreen" for details.
But tanoshimi isn't wrong. Anything but the most simple input system should probably be rewritten using the touchPad input commands.
Answer by pedrampk · Jul 15, 2018 at 04:03 PM
Input.GetMouseButtonDown(0) will be translate to single tap automatically. and the Input.mousePosition is translated to the position of tapped point.
Answer by tanoshimi · Jul 15, 2015 at 07:48 PM
Android devices, in the main, don't have mouse input. But some do. PCs, in the main, don't have touch input. But some do.
My point is that the way in which you handle mouse/touch input is independent of your target platform, and Unity can't guess what input system you want.
Secondly, touch/mouse are really very different anyway, and should be designed specifically to account for their own unique affordances: What would be the touch equivalent of a right click? What would be the mouse equivalent of a pinch gesture? Precise double-tapping is much harder than precise double-clicking, but swiping with a finger is easier than swiping with a mouse.
Input.touches gives you all you need to design touch interfaces, and you can use preprocessor directives to switch input schemes depending on platform as you choose.
I guess I will have to rework my project for touch interface. Thank you for the quick help!
Your answer
Follow this Question
Related Questions
After build doesnt work 0 Answers
Build EXE - Crashes 0 Answers
Lightmapping stuck at 3/15 baking resources 1 jobs 1 Answer
i5 or i7 for Unity Projects? 2 Answers
Textures from local works in editor missing in build 1 Answer