Version: 5.6
public GUIElement HitTest (Vector3 screenPosition);

설명

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.

See Also: GUIElement.HitTest, Input.mousePosition.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { private GUILayer test; void Update() { if (test.HitTest(Input.mousePosition) != null) Debug.Log(test.HitTest(Input.mousePosition).name); } void Example() { test = Camera.main.GetComponent<GUILayer>(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961