GUITexture HitTest touch area

Hi Everyone,

I’m trying to figure out what I’m doing wrong. I want to expand the a GUITexture.HitTest area so it’s easier to touch because the button is small (so it doesn’t clutter up the screen space), has anyone else figured this out?

var buttonB : GUITexture;

function OnGUI(){

	buttonB.transform.position = Vector3 (0,0,-1);
	buttonB.transform.localScale =Vector3 (0,0,0);
	buttonB.pixelInset = Rect (0,Screen.height - buttonB.pixelInset.height - 6,    buttonB.pixelInset.width,buttonB.pixelInset.height);

}

function Update (){
	
	for(var touch : Touch in Input.touches)
	{
		if(touch.phase == TouchPhase.Began && buttonB.HitTest(Vector3(Screen.width - buttonB.pixelInset.width,Screen.height - buttonB.pixelInset.height,0)))
		{
			Debug.Log("The News");
		}
   	}
}

I just want to point out that touch.position works fine but again the touch area isn’t big enough…HELP PLEASE!

P.S
This is for mobile so it needs a HitTest.

Hi ironcore1,
A few things :
1)Why adjust the button’s transform and pixelInset in OnGUI ? That will repeat the operation every frame, which surely isn’t what you want.

  1. Instead of using HitTest, you could create a new Rect that is bigger that the GUITexture and use Rect.Contains ( Vector2 touchPosition ) to check if the touch happened on your button.

  2. Do yourself a favour and invest in a GUI framework - NGUI is the most widely used out there. Unity’s GUI is cumbersome and inefficient, and will soon be completely overhauled by NGUI’s developper so you might as well start learning his way of doing things.

All the best!