How to select an ui image with mouse click and touch?

I have selected ui>image and I want to select that image with mouse click and touch

i also added a script with that image obj:

// It works fine while start
function Start(){
Debug.Log(gameObject.name);
}

// It’s not working
function OnMouseDown(){
Debug.Log(gameObject.name);

}

no collider or mesh randerer or rigid body attached just a script is attached

You will have to deal with Events triggers if you want to keep the Image script only. By the way, I don’t think it’s a good practice to add a button script + Image this way (since the button can already display an image)

See tutorial on events triggers : https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-events-and-event-triggers

Otherwise, you could only keep the button script and put the target graphic as you did. In that case, you can just :

  1. Click on the “+” button under the “On Click” panel of the button script
  2. Put the object where the desired function must be called
  3. Select the script + function to call when a click is detected on your button