Answer the question
In order to leave comments, you need to log in
How to track clicks on an object in Unity for mobile?
Hello users of Habr! The problem is that I can neither find nor think of a way to track when an object is touched across the screen. At first I used the OnMouseDown() method, but when compiling to apk, the engine complained about this.
Answer the question
In order to leave comments, you need to log in
The object needs a collider and the following script:
using UnityEngine;
using UnityEngine.EventSystems;
public class PointerListener : MonoBehaviour, IPointerDownHandler
{
public void OnPointerDown(PointerEventData eventData)
{
// Тут обрабатываем нажатие тачем или мышкой
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question