GUILayer.HitTest 位置检测

function HitTest (screenPosition : Vector3) : GUIElement


Get the GUI element at a specific screen position.


Returns the GUIElement at a specific point on screen. If screenPosition is inside some GUIElement, that element is returned. Returns null if the position is not inside any GUI element. GUI elements that belong to Ignore Raycast layer will be ignored, as if they would not exist.


screenPosition is measured in screen coordinates, like the values returned by Input.mousePosition property.


Note: GUILayer.HitTest only finds old-school GUI components (made up of the classes GUIElement, GUITexture, GUIText, GUILayer), and will not work with the "new" one (referred to as "UnityGUI" and made up of all the other GUIAnything classes, and the OnGUI() call).
So if you're using UnityGUI, HitTest won't find anything.

注意:GUILayer.HitTest只查找老式GUI组件(由类GUIElement, GUITexture, GUIText, GUILayer组成),并不会工作在新的组件上(被称为UnityGUI和由所有其他GUI什么的类组成,和OnGUI()调用)。因此如果你使用UnityGUI,HitTest将不会找到任何东西。

参见: GUIElement.HitTest, Input.mousePosition

Page last updated: 2010-12-25