Input.GetTouch(0) vs Input.GetMouseButton(0) that it is better to use in mobile devices?

I use to detection of a touch screen using Input.GetMouseButton(0), is this correct and will it affect the performance ? It seems to work all right, except for the detection of finger on the screen nothing else is needed(swipe, multitouch etc).
June 8th 19 at 16:31
1 answer
June 8th 19 at 16:33
The only difference will be when you tap the screen with two fingers and more GetTouch in this case, give the fact of pressing the first finger at the same time you can clean it up and leave the rest on the screen, and they will continue the second and third and so on. GetMouseButton will not distinguish between fingers and will only react to the fact of pressing (probably the last time I checked a couple years ago). In your case, you can use any method, no difference in performance will not. Please note that Input does not interact with the UI, which can lead to the fact that when you press the buttons you have extra time to work the logic.
Thank you, for that would when interacting with the UI did not work logic in the method Updete has the following line:
if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))

Is there any other way to detect clicking on UI elements? - maudie1 commented on June 8th 19 at 16:36
There , you need to make a transparent fullscreen button, which you will use to determine the taps instead of GetTouch and GetMouseButton:
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class TouchPanel : Graphic, IPointerClickHandler, IDragHandler, IPointerDownHandler, IPointerUpHandler
 onClick public DataEvent = new DataEvent();
 onDrag public DataEvent = new DataEvent();
 onPointerDown public DataEvent = new DataEvent();
 onPointerUp public DataEvent = new DataEvent();

 protected override void Reset()
 color = color.clear;

 public void OnPointerClick(PointerEventData eventData)

 public void OnDrag(PointerEventData eventData)

 public void OnPointerDown(PointerEventData eventData)

 public void OnPointerUp(PointerEventData eventData)

 public class DataEvent : UnityEvent<pointereventdata>

Just throw this component on the object and stuffing it under all the other interactive elements, then all pushing past the visible buttons will go into the code previously treated with GetMouseButton, only it will have a bit to rewrite, of course. - litzy commented on June 8th 19 at 16:39
OK, I will try, thank you! - maudie1 commented on June 8th 19 at 16:42

Find more questions by tags Unity Game Engine