Error when using GUITexture.HitTest

Hi

I’m trying to use GUI.Texture.HitTest(touch.position) to get the true or false bool when user touches the mobile screen.
I get the following error message: “BCE0019: ‘Hit Test’ is not a member of UnityEngine.GameObject.”

Here’s my code:

   var GUI_LeftArrow : GameObject;
    var GUI_RightArrow : GameObject;
    
    function Awake() {
    	GUI_LeftArrow = GameObject.Find("GUI_LeftArrow");
    	GUI_RightArrow = GameObject.Find("GUI_RightArrow");
    }
    
    function Update() {
    	for (var touch : Touch in Input.touches) {
    		if (touch.phase == TouchPhase.Stationary && GUI_LeftArrow.HitTest(touch.position)) {
    		Debug.Log("Left Arrow Down");
    		}
    	
    	}
    }

GameObject.Find is getting the GUITexture (Game Object) from the hierarchy panel in Unity.
Maybe I’m missing an import into the script at the top? Any help will be great.

Unity is right! HitTest is member of GUITexture, not of GameObject - you should use the guiTexture property of GUI_LeftArrow instead:

if (... && GUI_LeftArrow.guiTexture.HitTest(touch.position)){

NOTE: never use Find inside Awake - the objects you’re looking for may have not been created yet. Rename the function Awake as Start and potential headaches will be avoided.

GameObject doesn’t have a HitTest…but GUITexture does. So, you need to declare your variables a GUITexture not GameObject. Then you need to get the guiTexture property of the GameObject found in the Start Function as a GUITexture. Give this a try:

var GUI_LeftArrow : GUITexture;
var GUI_RightArrow : GUITexture;
 
function Start() {
    GUI_LeftArrow = GameObject.Find("GUI_LeftArrow").guiTexture;
    GUI_RightArrow = GameObject.Find("GUI_RightArrow").guiTexture;
}
 
function Update() 
{
    for (var touch : Touch in Input.touches) 
    {
       if (touch.phase == TouchPhase.Stationary && GUI_LeftArrow.HitTest(touch.position)) 
       {
           Debug.Log("Left Arrow Down");
       }
 
    }
}

Final Working Solution for detecting GUITexture touch events:

var GUI_LeftArrow : GUITexture;
var GUI_RightArrow : GUITexture;

function Start() {
	GUI_LeftArrow = GameObject.Find("GUI_LeftArrow").guiTexture;
	GUI_RightArrow = GameObject.Find("GUI_RightArrow").guiTexture;
}

function Update() {
	for (var touch : Touch in Input.touches) {
		if (touch.phase == TouchPhase.Stationary && GUI_LeftArrow.HitTest(touch.position)) {
		//if (touch.phase == TouchPhase.Stationary) {
		//if (GUI_LeftArrow.HitTest(touch.position)) {
		Debug.Log("Left Arrow Down");
		}
	
	}
}