I have a problem I’ve been struggling for last week. I’m currently making inventory system to my game and I can’t find any working way to detect mouse click on UI image. I was searching a lot and I need your help with figuring why NOTHING was working.
I won’t write about details, because that would be too long.
(If I made some mistakes in my english I’m really sorry)
1 Answer
1
I tested this quickly and it seems to work. I put this on an object with an Image component that was a child of the Canvas.
The scene needs the Event Handler which should have been automatically created when a Canvas was added to the scene.
using UnityEngine;
using UnityEngine.EventSystems;
public class UIClick : MonoBehaviour, IPointerClickHandler
{
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("Detected Click!");
}
}
Wierd. When I re-made everything in my scene it suddenly all started working. Thanks for your help anyways! :)
– theCheeseGuy