I'm working on a mobile game and I need to check if the user touches one of 2 game objects. My script looks like this:
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine;
public class PlayerControl : MonoBehaviour, IPointerClickHandler {
public void OnPointerClick(PointerEventData eventData) {
Debug.Log("Clicked: " + eventData.pointerCurrentRaycast.gameObject.name);
}
}
The code I got from: this stackoverflow post, but it still doesn't work for me.
My 2 game objects have the script, a rigidbody 2d and a box collider 2d..
When I click on the gameobjects, it doesn't log to the console. And the event mask is correct.
Can someone help me?