TestCShape.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. public class TestCShape : MonoBehaviour
  7. {
  8. GraphicRaycaster RaycastInCanvas;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. RaycastInCanvas = GameObject.Find("Canvas").GetComponent<GraphicRaycaster>();
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. if (Input.GetMouseButtonDown(0))
  18. {
  19. IsPointerOverGameObject();
  20. }
  21. }
  22. private void IsPointerOverGameObject()
  23. {
  24. PointerEventData eventData = new PointerEventData(EventSystem.current);
  25. eventData.pressPosition = Input.mousePosition;
  26. eventData.position = Input.mousePosition;
  27. List<RaycastResult> list = new List<RaycastResult>();
  28. RaycastInCanvas.Raycast(eventData, list);
  29. print(list.Count);
  30. for (int i = 0; i < list.Count; i++)
  31. {
  32. print(list[i].gameObject.name);
  33. }
  34. }
  35. }