Unity3d--判断鼠标是否触发UGUI控件

 1 void Update () {
 2         //判断鼠标左键是否按下其没有按下UGUI物体
 3         if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) {
 4             //获取由主摄像机位置到鼠标点击位置的一条射线
 5             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 6             RaycastHit hitInfo;
 7             //bool isCollider = Physics.Raycast (ray, out hitInfo,1000,LayerMask.NameToLayer("Ground"));
 8             bool isCollider = Physics.Raycast(ray,out hitInfo);
 9             //Debug.Log (isCollider);
10             //判断射线是否成功发射且是否触发目标物体
11             if (isCollider && hitInfo.collider.tag == "Ground") {
12                 //参数为目标物体的位置信息
13                 ShowClickEffect (hitInfo.point);
14                 isMoving = true;
15                 LookAtTarget (hitInfo.point);
16                 //Debug.Log ("007");
17             }
18         }
posted @ 2016-06-17 15:43  yuge790615  阅读(958)  评论(0编辑  收藏  举报