Get clicked object cords on object ? Unity2D

Hello folks!
I’m doing some tests with clicking object and what do get clicked object cords on object. 33524-touches.png

I think image show exactly what i want to achieve.
Here is my click call block:

checkPosition (Input.GetTouch (0).position);

And here is function that is called from this block.

private void checkPosition(Vector2 vec){
				Vector3 wp = Camera.main.ScreenToWorldPoint (vec);
				Vector2 touchPos = new Vector2 (wp.x, wp.y);
				var hit = Physics2D.OverlapPoint (touchPos);

				if (hit) {
					Debug.Log(hit.transform.gameObject.name);
					Debug.Log(hit.transform.position.x + " | " + hit.transform.position.y);	
					hit.transform.gameObject.SendMessage("Touched",0,SendMessageOptions.DontRequireReceiver);
				}
	}

Any advice will be great how to get thous cords.

The solution will vary depending on the type of object. The easiest would be a Quad.

  • Convert the point to a local coordinate using Transform.InverseTransformPoint()
  • Add (0.5, 0.5, 0.0) to the result. This is because coordinates are relative to the pivot, and the pivot is in the center. By adding this vector, you are placing the origin in the lower left corner.
  • Multiply the result by the Transform.localScale