Guest User

Untitled

a guest
Aug 3rd, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4.  
  5. public static class UIHelper
  6. {
  7.     private static List<RaycastResult> results = new List<RaycastResult>();
  8.     public static List<RaycastResult> RaycastMouse()
  9.     {
  10.         PointerEventData pointerData = new PointerEventData(EventSystem.current)
  11.         {
  12.             pointerId = -1,
  13.         };
  14.  
  15.         pointerData.position = Input.mousePosition;
  16.         results.Clear();
  17.         EventSystem.current.RaycastAll(pointerData, results);
  18.         return results;
  19.     }
  20.  
  21.     public static bool IsOnUi()
  22.     {
  23.         var r = RaycastMouse();
  24.         foreach (var result in r)
  25.         {
  26.             if (result.isValid)
  27.                 return true;
  28.         }
  29.         return false;
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment