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.
// 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]()