GUI Text alignment with moving camera in Unity
<p>I am making a top-down shooter type of game in Unity. The player can move in the world, but the camera moves with him, so the player is always in the middle of the screen.</p>

<p>I'm trying to display some text in the upper-left corner of the screen, and so I attached a GUItext component to the main camera. The result was quite interesting - the moment the player moves the text darts off the screen.</p>

<p>What the text is supposed to display is controlled by the player, so I added the following snippets of code in my player script:</p>

<pre><code>public GUIText scoreText;
void Update ()
    {
        scoreText.pixelOffset = new Vector2 (300, 300);
    }

void UpdateScore ()
    {
        scoreText.text = "Lives: " + lives;
    }
</code></pre>

<p>but that didn't change anything, and the <code>void UpdateScore ()</code> didn't work either.</p>

<p>I am rather new to Unity, so this is probably a very simple mistake... but what am I doing terribly wrong?</p>

<p>EDIT: the <code>void UpdateScore ()</code> works now that I call from <code>void FixedUpdate ()</code>.</p>

<p>EDIT (again): I fixed the problem by making a new Empty Object with nothing in it except the transform (which never moves) and a GUI text component. The problem I have now is that the anchor on the GUI text works very strange - it only works if I put it on the lower-left (whereas I want it on the upper left). Trying to change the anchor moves it somewhere off the screen. Here's my hierarchy: <a href="https://i.stack.imgur.com/YErWw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YErWw.png" alt="enter image description here"></a></p>