I’m trying to write a script for a UI object that will detect when it is clicked on and be able to tell what kind of click it was (i.e. left click or right click). So far I just have a basic test script (written in Unityscript):
function Start () {
}
function Update () {
}
function OnPointerClick(data : UnityEngine.EventSystems.PointerEventData) {
print("Detection");
}
What I want it to do is print “Detection” whenever I click on it, but that isn’t happening (eventually, I will look at the “data” variable to see what kind of click it was). What am I missing?
All ponter events will not trigger if clicked object is situated near the “far clipping plane” of the camera.
There can be situation when object is seen in the scene but it doesn’t trigger pointer events because is situated too near to the camera far border.
Was totally surprised by the fact and spent a lot of time solving this.
Add Button component for your GameObject (in my case it was an Image with zero in alpha just to cover some area). Without it OnPointerClick() implemented from IPointerClickHandler was not triggered