Get Pixel Coordinate When Click On 2D Object

Hei all,,

Sorry if this has been asked before, but I couldn't find a good solution to it yet.

I have one object for example cube. When I clicked on that cube, I wanna get pixel coordinate of the point where I clicked there .

Could you help me guys? Please... I dont have idea to solve.

Thanks

Raycast from the camera to mouse position and use the RaycastHit.point to get the impact position. Then use Camera.WorldToScreenPoint to get the screenspace (pixel coordinate) of the impact.

function Update ()
{
   if ( Input.GetMouseButtonDown(0) )
   {
      var hit : RaycastHit;
      var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
      if (Physics.Raycast (ray, hit, 100.0))
      {
         var hitPos : Vector3 = Camera.main.WorldToScreenPoint(hit.point);
         Debug.Log(hitPos);
      }
   }
}

You'll usually have better success finding answers if you break it down to its basic parts. The raycast (object selection) script came from another answer, and there are plenty of other questions about converting world space to screen space.