I have a plane that contains around 200 tiles, and I'd like to be able to detect which tile has been clicked by the player. Each tile has a box collider attached. I've also created an empty game object in the scene to which I attached EventSystem
and the below script:
public class PlaneBehaviour : MonoBehaviour, IPointerDownHandler {
public GameObject ClickSymbol;
public void Start() {
var physicsRaycaster = FindObjectOfType<PhysicsRaycaster>();
if (physicsRaycaster == null) {
Camera.main.gameObject.AddComponent<PhysicsRaycaster>();
}
}
public void OnPointerDown(PointerEventData eventData) {
var o = eventData.pointerCurrentRaycast.gameObject;
}
}
Now, when user clicks anywhere, nothing happens - I've put a breakpoint inside the OnPointerDown
method, but it's not getting hit (and the code inside the Start
method is run - I've also verified that by putting a breakpoint in there).