言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

GUILayer.HitTest

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public function HitTest(screenPosition: Vector3): GUIElement;
public GUIElement HitTest(Vector3 screenPosition);
public def HitTest(screenPosition as Vector3) as GUIElement

Description

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

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.

	// Tests if the mouse is touching a GUIElement.
	// Add a GUITexture and put the mouse over it and
	// it will print the GUITexture name.
	private var test : GUILayer;
	test = Camera.main.GetComponent(GUILayer);
	function Update() {
		if(test.HitTest(Input.mousePosition) != null) {
			Debug.Log(test.HitTest(Input.mousePosition).name);
		}
	}
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>();
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	private test as GUILayer

	def Update() as void:
		if test.HitTest(Input.mousePosition) != null:
			Debug.Log(test.HitTest(Input.mousePosition).name)

	def Example() as void:
		test = Camera.main.GetComponent[of GUILayer]()