堡主大名花花

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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);

    }

}

 

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            point.z = transform.position.z;
            if (sprite.bounds.Contains(point))
            {
                ctrl.fsm.PerformTransition(Transition.PieceClick);

            }

        }
    }


posted on 2019-12-19 21:46  堡主大名花花  阅读(447)  评论(0编辑  收藏  举报