How can I convert a world space point to screen, with canvas scaling?

I want to make a button in my GUI position itself based on the position of an object in world space.

I’m using the new 4.6 GUI.

My canvas’s scale mode is set to Constant Physical Size, so that I can specify the size of things in millimeters.

I’ve already tried camera.WorldToScreenPoint(position), which gave me a value that was far too large, presumably because it didn’t account for scaling.

GUIUtility.ScreenToGUIPoint() sounded like what I was looking for but it just gives me 0 when I pass in that previous value.

Any ideas?


Vector3 screenPointUnscaled = camera.WorldToScreenPoint (worldPoint);
return screenPointUnscaled.x / canvas.scaleFactor;

Works so far (I only needed the X position).