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 als
There are many things that could cause the callback function not being called. Before trying these, put Debug.Log
inside the OnPointerDown
function to make sure that it's being called:
1.Go to GameObject-->UI--->EventSystem.
A GameObject named "EventSystem" will be created and will proper scripts such as EventSystem
, StandAloneInputModule
attached to it.
2.The PlaneBehaviour
script must be attached to the GameObject with the Collider not to an empty GameObject. It detects click on the Objects it is attached to.
3.If you are using a collider that ends with "2D" in its name then Physics2DRaycaster
must be used instead of PhysicsRaycaster
.
4.Are you using more than two cameras? If so manually attach PhysicsRaycaster
to the correct Camera that is currently showing that Object.
5.Re-size the GameObjects you want to detect clicks on to be bigger. I've seen doing this solve the problems sometimes. You then have to move the camera back if this works.