canvas射线检测

public class someclass:monobehaviour

{

    public EventSystem eventssystem;
    public GraphicRaycaster gra;
    ///


    /// 射线检测
    ///

    ///
    ///
    public bool MouseOver(string Name)
    {
        var mPointerEventData = new PointerEventData(eventssystem);
        mPointerEventData.position = Input.mousePosition;
        List results = new List();

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

    }

}

你可能感兴趣的:(canvas射线检测)