Click through Transparent Parts of Image

I’m trying to use images to build a board of irregularly shaped portions, however the bounding box for some of the irregular shaped parts overlap and it detects the click on the top element instead of the element that has the graphic below this. Is there some way to apply a selection mask or something to limit what regions of the graphic can detect a click?

Hi there, I might use recasting for something like this so that only the element that you click on will be affected.

Example:

	public float sensitivity = 1.0f;
	private GameObject gameObjectToMove;

	void LateUpdate () 
	{
		// Click and Drag Mechanic
		Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);

		if(Input.GetMouseButtonDown (0))
		{
			RaycastHit2D hit = Physics2D.Raycast(pos, transform.position);

			if (hit.collider != null && hit.collider.gameObject.layer == LayerMask.NameToLayer("WhateverLayerYouWant")) 
			{
				gameObjectToMove = hit.collider.gameObject;
			}
		}

		if(Input.GetMouseButton (0) && gameObjectToMove != null)
		{
			gameObjectToMove.transform.position = new Vector3(pos.x, pos.y, 0);
		}
		
		if(Input.GetMouseButtonUp (0) && gameObjectToMove != null)
		{
			gameObjectToMove = null;
		}	

	}

Clicks are detected by colliders. So if you want a more complex hit-detection, you’ll need to add a mesh collider (or create a composite collider) that excludes those areas on which you don’t want to be able to click.