title: Getting world position to canvas position for Screen Space - Camera canvas
body: <p>I'm trying to make a text display over a cube in Unity UI when I freely move my camera. The canvas is set to Screen Space - Camera mode and I set the camera property in the inspector. I have also attached a mouse move script to the camera.</p>
  
  <p>My problem is that the text is barely moving and seems to ignore the position of the cube relative to the camera's viewport. Here is my code:</p>
  
  <pre><code>public class UpdateUiMarker : MonoBehaviour {
  
      public RectTransform element;
      public Transform cube;
  
      public RectTransform canvas;
  
      // Update is called once per frame
      void LateUpdate () {
          Vector2 screenPos = Camera.main.WorldToScreenPoint(cube.position);
          Vector2 localPos;
          RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas, screenPos, Camera.main, out localPos);
          element.localPosition = localPos;
      }
  }
  </code></pre>