How to transcode OnMouse to Touch phase for Android?

Hello forum. I’m stuck to a rather simple solution, with my script transcoded to Android. I’m having a gameObject “Cube”, and a script attached for rotation.

Also I’ m having a script “ClickButton” attached to a GUI.Texture. Everything works o.k. in Player, but I want to transcode this script to be used by touches in Android. Problem is I can’t do it, although I have read the Unity documentation.

Here is the code snippet:

//This script is attached on a GUI.Texture acting as a button

var normalTexture : Texture2D;
var hoverTexture : Texture2D;

function Update(){

        for (var i = 0; i < Input.touchCount; ++i) {
            if (Input.GetTouch(i).phase == TouchPhase.Began)
          
            var rotate = Input.GetTouch(i);
            rotate == doRotate();
                }
            }

function OnMouseEnter(){

guiTexture.texture = hoverTexture;

}

function OnMouseExit(){

guiTexture.texture = normalTexture;

}

function OnMouseDown(){  
    var runScriptRotate : GameObject[] = GameObject.FindGameObjectsWithTag("Marker");   
                for(var doRotation : GameObject in runScriptRotate)
                    {   
                    var scriptRT : doRotate = doRotation.GetComponent(doRotate);   
                        if(scriptRT)
                        {
                        // access the function "doRotation" on a script named "doRotate" on gameObject "Cube"
                        doRotate.doRotation();
                        }   
                    }     
                   }

Can someone, be kind enough to post an edit to my code script, to make it work on Android by touching? Thank you all in advance!

You can use if(Input.GetMouseButtonDown(0)), which will act as “left mouse button” and also “touch” for smartphones.

Hi @Sykoo , thanks for reply. I’ve tried what you suggested, nothing happened. I have attach the script on GUITexture, on MainCamera, nothing happens. Can you edit my above code, with a GUITexture, working as button?

I’m going for vacation tomorrow so I have to pack now, but I’ll see if I can answer yoiu later :slight_smile:

Thank you @Sykoo . Hope you can still make it. Have a nice time at your vacation! :sunglasses:

Thanks bud! :smile:
I iwll try my best :slight_smile: