Variable in GUI.TextField not updating

Hello,

I’m having a problem with GUI.TextField. When I use it to create a textfield that shows how long you have been playing. It won’t update and is stuck at a fixed number.
My code is as follows:

void Update () {
        m_Time += UnityEngine.Time.deltaTime;
        stringToEdit = stringToEdit + m_Time.ToString();
	}

void OnGUI()
    {
        stringToEdit = GUI.TextField(new Rect(Screen.width - 200, Screen.height - 50, Screen.width - 30, Screen.height - 30)
            , stringToEdit, 25);
        PlayerPrefs.SetString("", stringToEdit);
    }

Also, I have to use UnityEngine.Time.deltaTime otherwise if I use Time.deltaTime, deltaTime gives the error “Time does not contain a definition for deltaTime”.
Don’t know if that’s got anything to do with it, just thought I’d mention it.

The problem is that you’re appending to your string over and over with stringToEnd = stringToEdit + mTime.ToString(). This makes your string grow and grow and grow. Because you’ve set a fixed length in the TextField, you only see the start/first time that you sampled.

If you just want to display text to the user, use GUI.Label.

Also, your “Time does not contain” issue is because you don’t have using UnityEngine; at the top of your file.