OnPointerClick function not triggering

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) {

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?

You need implements:

import UnityEngine.UI;
import UnityEngine.EventSystems;

public class TestEvents extends MonoBehaviour implements
/*...etc*/ {

	function OnPointerEnter(eventData : PointerEventData) {
		Debug.Log("Pointer Enter");
	function OnPointerExit(eventData : PointerEventData) {
		Debug.Log("Pointer Exit");
	function OnPointerClick(eventData : PointerEventData) {
		Debug.Log("Pointer Click");
	function OnPointerUp(eventData : PointerEventData) {
		Debug.Log("Pointer Up");
	function OnPointerDown(eventData : PointerEventData) {
		Debug.Log("Pointer Down");
	function OnSelect(eventData : BaseEventData) {

Your class name and file name must b match! (I call it “TestEvents”.)

For anyone coming to this question, you may also try adding a Physics Raycaster component to your active camera, and enabling an appropriate layer.

Another one hint:

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.

Another important hint:
Check the EventSystem gameobject of the scene. The “Standalone Input Module” has to be enabled!

I disabled it to remove the “Submit” and “Cancel” input but then the mouse events are not triggered anymore.

For me worked 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

Can anyone tell me how to use scrollrect.OnScroll(PointerEventData data)