Hittest | Left or Right Screenside

I have this two rects:

LeftRect = new Rect(0, 0, Screen.width / 2, Screen.height);
RightRect = new Rect(Screen.width / 2, 0, Screen.width / 2, Screen.height);

The “LeftRect” creates an image on the left side of the screen and “RightRect” creates an image on the right side of the screen. And how can I get the information, that one of that is touched on my Android device? I don’t know, how to use “Hittest”.

foreach (Touch touch in Input.touches)
        {
            if (touch.phase == TouchPhase.Began)
            {
                Ray ray = Camera.main.ScreenPointToRay (touch.position);
                RaycastHit hit = new RaycastHit();
                if (Physics.Raycast (ray,out hit,1000.0f))
                {
                    if(hit.collider.gameObject == this.gameObject)
                    {
                        Debug.LogWarning(hit.transform.name);
                        
                    }
                }
            }
        }

don´t forget to assign a collider to your gameobject. Also you need a Camera which has the tag “MainCamera”.

This checks if I touch a collider and not the image?

If u want to use GUITexture then use

void OnMouseUpAsButton()
{
   //ur code
}

Does this also work at Android touchscreens?

create guitexture and add the script.Its works fine.

I created this Texture:

GUI.DrawTexture(LeftRect, links);

And how can I use ith with
void OnMouseUpAsButton()
?

U need to create GUITexture gameobject in hierarchy.Then add the script for that gameobject.

But I have created the GUI with a script and not in the hierarchy.