convert world to screen (crosshair follow)

hi! help with converting in screen coords. I made crosshair following where is muzzle of tank aims.
But i can’t convert world coord in screen rightly.

if(Physics.Raycast(firePoint.position, firePoint.TransformDirection(Vector3.left), out hit))
        {
                Debug.DrawLine(firePoint.position,hit.point,Color.red);
                
// Vector 3 of hit.gameobject
                pointCursor = Camera.main.WorldToScreenPoint(hit.transform.position);
        
       }

        void OnGUI()
        {
                Vector2 vector2 = GUIUtility.ScreenToGUIPoint(new Vector2(pointCursor.x, pointCursor.y));
                Rect labelRect = new Rect();
                labelRect.x = vector2.x;                
                labelRect.y = vector2.y;
                labelRect.width = cursorTexture.width;
                labelRect.height = cursorTexture.height;

                GUI.DrawTexture(labelRect,cursorTexture);
        }

You should use hit.point: this returns the 3D point where your raycast hit something. If you use hit.transform.position, the crosshair will be located at the hit object’s pivot: looks weird for small objects, and completely wrong for the bigger ones.

...
if (Physics.Raycast(firePoint.position, firePoint.TransformDirection(Vector3.left), out hit)){
  // Use the hit point instead:
  pointCursor = Camera.main.WorldToScreenPoint(hit.point);
}
...

NOTE: The crosshair will be rendered even if the raycast doesn’t hit anything, what may seem weird. You can avoid this using a boolean variable like this:

private var hitSomething: boolean; // <- declare this variable

  ...
  // assign the raycast result to it:
  hitSomething = Physics.Raycast(firePoint.position, firePoint.TransformDirection(Vector3.left), out hit);
  if (hitSomething){
    // Use the hit point:
    pointCursor = Camera.main.WorldToScreenPoint(hit.point);
  }
  ...

function OnGUI(){
  if (hitSomething){ // only draw the crosshair if something hit:
    Vector2 vector2 = GUIUtility.ScreenToGUIPoint(new Vector2(pointCursor.x, pointCursor.y));
    ...
    GUI.DrawTexture(labelRect,cursorTexture);
  }
}