How to detect mouse or touch input on a Sprite?

I have a sprite acting as a GUI and I want to be able to detect mouse and touch input on it.

This is how I have my code

void Update()
	{
		RaycastHit hitInfo = new RaycastHit();
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		
		// OnMouseDown
		if (Input.GetMouseButtonDown(0))
		{
			if (Physics.Raycast(ray, out hitInfo))
			{
				Debug.Log("hit");
			}
		}
	}

When I click, it doesn’t log “hit” like I want it to.

Use OnMouseDown instead?