UIManager.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.EventSystems;
  6. public class UIManager : MonoBehaviour
  7. {
  8. private GraphicRaycaster raycaster;
  9. private PointerEventData eventData;
  10. private EventSystem eventSystem;
  11. public Transform selectionPoint;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. raycaster = GetComponent<GraphicRaycaster>();
  16. eventSystem = GetComponent<EventSystem>();
  17. eventData = new PointerEventData(eventSystem);
  18. eventData.position = selectionPoint.position;
  19. }
  20. // Update is called once per frame
  21. void Update()
  22. {
  23. }
  24. public bool OnEnetered(GameObject button)
  25. {
  26. List<RaycastResult> results = new List<RaycastResult>();
  27. raycaster.Raycast(eventData, results);
  28. foreach(var result in results)
  29. {
  30. if(result.gameObject == button)
  31. {
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. }