canvas射线检测

public class someclass:monobehaviour

{

    public EventSystem eventssystem;
    public GraphicRaycaster gra;
    /// <summary>
    /// 射线检测
    /// </summary>
    /// <param name="Name"></param>
    /// <returns></returns>
    public bool MouseOver(string Name)
    {
        var mPointerEventData = new PointerEventData(eventssystem);
        mPointerEventData.position = Input.mousePosition;
        List<RaycastResult> results = new List<RaycastResult>();

        gra.Raycast(mPointerEventData, results);
        return results.Any(data => data.gameObject.name == Name);

    }

}