Making a GUI Texture tappable on iPhone

Disclaimer: I’ve searched everywhere for this, including the Unity documentation.

In the Unity simulator, this works fine if I add a script like this to my GUITexture in the hierarchy:

function OnMouseUp (){
		//do stuff
}

However when run on the iPhone, this doesn’t have any effect. After a bit of searching I tried:

if(Input.touchCount>0){
//do stuff
}

This doesn’t appear to do anything in the simulator or on the handset.

One thing that does work fine on the iPhone is building a GUIButton like this:

function OnGUI() {
	
    	if(GUI.Button(Rect(0,400,320,44),"I'm a code generated button!")) {
    		//do stuff		
    		}
    }

However this is code for dynamically drawing a button, not code for placing on a GUITexture game object.

Any clues? :frowning:

Actually, I fixed this by looking at some Android questions!!

Here’s the ballache answer (you need to do this per button… ):

function Update(){
	if (Input.touchCount == 1)
	{
	var touch: Touch = Input.touches[0]; 
	
	if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
	
		{
		// do amazing things
		} 
	}
}

,how do you use this with multiple touches?

Lets say you have 2 GUITextures and you want each of them to have independent touches, how do you modify the code so that you

how do you use this with multiple touches?

Lets say you have 2 GUITextures and you want each of them to have independent touches, how do you modify the code so that you if you touch the 1 texture if activates, touching the other activates that one aswell and releasing either of them deactivates the one released…
Same works if they are touched independently

I have some problem, i want do something like this:

When i tap guitexture it change from texture1 to texture2, so i combine two scripts this for tap and this:

var texture1 : GUITexture;
var texture2 : GUITexture;

var someTexture : GUITexture;
someTexture = texture1;
guiTexture.texture = texture1.texture;

function Update () {
}

function OnGUI() {

    if(GUI.Button(Rect(0,0,100,40),"Cambia fondo")){
        if(someTexture == texture1) {
            someTexture = texture2;
        } else if (someTexture == texture2) {
            someTexture = texture1;
        }   

    }
}

for change GUITexture

but first what i do is check this script, it work but GUITexture are not change on screen in inspector i see changes texture1 to texture2

I want do something like this:

var texture1 : GUITexture;
var texture2 : GUITexture;

var someTexture : GUITexture;
someTexture = texture1;
guiTexture.texture = texture1.texture;


function Update(){
    if (Input.touchCount == 1)
    {
    var touch: Touch = Input.touches[0]; 

    if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))

       {
        if(someTexture == texture1) {
            someTexture = texture2;
        } else if (someTexture == texture2) {
            someTexture = texture1;
        }   
       } 
    }
}

I search 2h for something and i cant find anything, so… somebody can help me?