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.
-
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).
-
A cube with default values.
-
A Camera called Main Camera
-Has a Physics Raycaster on it
-Has an Event System on it
-
A default directional light
-
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!