Hello, I’ve tried all of the different events and the don’t seem to be working. I’ve been inheriting from IPointerClick Hander and implementing the interface but nothing seems to be working. Any ideas?
The code for reference:
public class Slot : MonoBehaviour, IPointerClickHandler
public void OnPointerClick(PointerEventData eventData)
Is there an eventsystem in your scene? Does your camera have a physics raycaster on it? (Or does the canvas in which this element is contained have a graphic raycaster on it?)
Perhaps something is blocking the thing you are trying to click. When in play mode highlight the EventSystem and look at it in the inspector. If the name of the thing you want to click is not showing up then it is never called.
The GameObject where your script is attached to has to have another component attached that is derived from UI.Graphic. Like one of the built-in components: Image, RawImage or Text. Only GameObjects which have a Graphic attached can actually be interacted with since the GraphicsRaycaster, as the name suggests, can only detect Graphics.
Graphic is an abstract class. However it adds itself to a global Graphic registry which is used by the raycaster. So only GameObjects which are registrated in that manager can actually be “hit”.
You can create a pure event target class like this:
public class EventTarget : Graphic
protected override void OnPopulateMesh(VertexHelper vh)
Just attach it to the same GameObject and you will receive your events. This is basically an empty Graphic as it does not generate any triangles / vertices. So this is a bit more efficient than using an Image with alpha set to 0 as it would still generate the quad and it would still be rendered.