【问题标题】:IsPointerOverGameObject get the gameobjectIsPointerOverGameObject 获取游戏对象
【发布时间】:2017-04-13 11:01:20
【问题描述】:

我想知道用户将鼠标指向哪个对象。

我发现我可以知道他何时指向一个 (IsPointerOverGameObject),但我找不到获取该游戏对象的方法。 http://docs.unity3d.com/460/Documentation/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html

我真的必须手动对 UI 进行光线投射吗?

【问题讨论】:

    标签: unity3d raycasting


    【解决方案1】:

    我会使用事件触发器来检测与 UI 元素的交互(也许 Pointer Down 是你想要的?)而不是在这里搞乱光线投射。

    【讨论】:

      【解决方案2】:

      这就是你的做法,你发送一个光线投射。

      if(Input.GetMouseButtonDown(0)) 
      {                    
          RaycastHit hit = new RaycastHit();
          Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      
          if(Physics.Raycast(ray, out hit))
             print(hit.collider.transform.gameObject.name);
      }
      

      【讨论】:

      • 更像是:List<RaycastResult> raycastResults = new List<RaycastResult>(); EventSystem.current.RaycastAll(eventData, raycastResults); 谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多