Touch Detection on Image

Hi. I am very new to unity so please excuse any silly/stupid errors. I am trying to detect touch on an Image that has been added to a Panel under the Canvas. I have added a sphere collider to the image and in the update function have written the following:

if (Input.GetMouseButtonDown(“0”))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, outhit))
{
Debug.log(hit.transform.gameObject.tag);
}
}

The problem is, it never flow never gets to the debug log.Any idea what Im doing wrong?

Why don’t you just make it a button?

I can’t make it a button as I have multiple images and I should be able to select multiple objects at one go. Like touch on one and then move my finger/mouse pointer over the others and select them as I move across them.

OK, then you want to add an “Event Trigger” and use “Add New Event Type” to add a “Pointer Down” event handler.

1 Like

Thanks for the tip. Will try that out.

Select Image from Canvas Go
AddComponent > EventTrigger > AddNewEventType > OnpointerDown

Then drag the scripting object that holds the function or trigger on anythings
Hope it Helps

1 Like

Works like a charm
Thank you

Thnak you xainulabdeen, You save my day