Created
December 13, 2022 12:33
-
-
Save pferreirafabricio/0a1bffdb8e6892b2307e903911afcee6 to your computer and use it in GitHub Desktop.
Method to check if a canvas element was clicked on Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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