Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

GUILayer.HitTest

マニュアルに切り替える
public GUIElement HitTest(Vector3 screenPosition);

パラメーター

説明

指定するスクリーン座標に GUI 要素があるか確認します

スクリーン上の特定のポイントで GUIElement を返します。 screenPosition がいくつかの GUIElement内にある場合、 そのエレメントが返されます。 GUI エレメントの内部に配置されていない場合、 null を返します。 存在しない場合、 Ignore Raycast レイヤーに属する GUI エレメントは無視されます。

screenPosition は Input.mousePosition プロパティーに返される値のようなスクリーン座標で測定されます。

注: GUILayer.HitTest は ( GUIElement、GUITexture、GUIText、GUILayerクラスでつくられた ) 古いけども使える GUI コンポーネントのみ検索し、 ( OnGUI() 呼び出しで他のすべての GUIAnything クラスで作られた"UnityGUI"と呼ばれる) made up of all the other GUIAnything classes, and the OnGUI() call).
だから、 UnityGUI を使用している場合、 HitTest は何かを検索することはできません。

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