How do I set up a GUITexture as a functional button?

I wrote details on what I’m trying to do with notes in the script:

//This is the script from Unity's FPS tutorial.

function Start () {
	SelectWeapon(0);
}

function Update () {
        //Works fine with the touch input, but I want my GUITexture do that job
	if (Input.touchCount > 0 && 
      Input.GetTouch(0).phase == TouchPhase.Began)

      //I don't need weapon switching

	if (Input.GetKeyDown("1")) {
		SelectWeapon(0);
	}	
	else if (Input.GetKeyDown("2")) {
		SelectWeapon(1);
	}	
}

function SelectWeapon (index : int) {
	for (var i=0;i<transform.childCount;i++)	{
		// Activate the selected weapon
		if (i == index)
			transform.GetChild(i).gameObject.SetActiveRecursively(true);
		// Deactivate all other weapons
		else
			transform.GetChild(i).gameObject.SetActiveRecursively(false);
	}
}

I’d highly appreciate a reply. I hope you understand my question.

All you need to do is create a new script and add that script to your GUITexture object. Then add an OnMouseDown( ) method to the script and do whatever you want to do inside that.

var btnTexture : Texture;
function OnGUI() {

if (GUI.Button(Rect(10,10,50,50),btnTexture)){
    Debug.Log("Clicked the button with an image");
}

Use GUILayer.HitTest():

http://unity3d.com/support/documentation/ScriptReference/GUILayer.HitTest.html

Or if you want to implement your own hit test, you can compare the current mouse position on a click with a GUIElement using GUIElement.GetScreenRect().

Here you go bro:

var fireButton : GUITexture;

function Update(){

for (var evt : Touch in Input.touches)
{

var HitTest1 =
fireButton.HitTest(evt.position);

if (evt.phase == TouchPhase.Began) {

if(HitTest1){

//do something when button is hit

Debug.Log (“ButtonGUI Clicked”);

fireButton.enabled = false;

} } } }

Just rememberto set a texture in the inspector :wink: