Event Trigger and Click Handler on 3D Object (Cube) Problem

Hello,

I want to have a function called when I click on a 3D object and I am trying to use and Event Trigger since I’m following along with the Adventure Sample Game tutorial from Unity.

I have a simple setup that I can’t get to work no matter what I do.

Here is my setup:
I have 5 objects in my scene.

  1. A cube collider which has:
    -A box collider that is the size of the cube
    -Event Trigger for Pointer Up which calls a function called “HandleClick” in the ClickHandler script which is attached to a game object that is also called “ClickHandler”. I set up this connection in the Editor (although I have also created the event trigger through code and it doesn’t work there either).

  2. A cube with default values.

  3. A Camera called Main Camera
    -Has a Physics Raycaster on it
    -Has an Event System on it

  4. A default directional light

  5. A game object with the Click Handler Script attached.

Here is the Code for the Click Handler:

using UnityEngine;
using UnityEngine.EventSystems;

public class ClickHandler : MonoBehaviour
{
    public void HandleClick()
    {
        Debug.Log("Cube Clicked");
    }
}

I am using Unity version 2018.3.5f1 Personal.

I have searched everywhere and tried everything I can think of but I can’t figure out what I’m missing. Can anyone see where I’m going wrong? Any help would be greatly appreciated. Thanks!

Update
Here are some more things I have tried, but I’m still having the problem.

-Uninstall and reinstall Unity
-use Graphics Raycaster instead of Physics Raycaster
-Put the ClickHandler script on the cube collider

This seems like a very simple case, can’t figure out what I’m missing. Any suggestions would be great.

Update
I finally managed to solve this issue. If anyone else is having the same problem, the answer was that I was missing a component for this to work. I needed to add a “Standalone Input Module”. I added it to the same object as the Event System and everything worked.

2 Likes

Did you try to debug, which gameobject you are hitting with the physics raycaster? Maybe your collider or your mesh is stopping the other to be reached.

gracias…