Skip to content

Instantly share code, notes, and snippets.

@pferreirafabricio
Created December 13, 2022 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pferreirafabricio/0a1bffdb8e6892b2307e903911afcee6 to your computer and use it in GitHub Desktop.
Save pferreirafabricio/0a1bffdb8e6892b2307e903911afcee6 to your computer and use it in GitHub Desktop.
Method to check if a canvas element was clicked on Unity
public class CanvasUtils
{
private bool HasClickedOnCanvasElement()
{
PointerEventData pointerData = new PointerEventData(EventSystem.current);
List<RaycastResult> results = new List<RaycastResult>();
pointerData.position = Input.mousePosition;
Raycaster.Raycast(pointerData, results);
return results.Count > 0;
// foreach (RaycastResult result in results)
// {
// Debug.Log("Hit " + result.gameObject.name);
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment