Display Playerpref string in GUI.TextField.

Hey, i've got some trouble as im trying to display a Playerpref string in a gui textfield, heres the code:

var name1 : String = PlayerPrefs.GetString("Player1 Name");
var namevar1 : String;

function OnGUI () { 
        GUI.Box (Rect (10, 40,500,500), ""); 
        GUI.Label (Rect (20, 50,100,20), "Spelare #1 - ");
        namevar1 = GUI.TextField (Rect (90, 50,100,20), ""+name1);
        PlayerPrefs.SetString("Player1 Name", namevar1);
        //player1lvl = GUI.TextField (Rect (195, 50,100,20), ""+player1lvl);
        //PlayerPrefs.SetString("Player1 Level", player1lvl);
        //p1use = GUI.TextField (Rect (300, 50,15,20), ""+p1use);
        //PlayerPrefs.SetString("Player1 Use", p1use);
}

Made lines that ain't relevant right now comments. Thanks in advance!

Current code:

var playerName : String;

function OnEnable() {
    playerName = PlayerPrefs.GetString("Player1 Name", "Player 1");
}

function OnDisable() {
    PlayerPrefs.SetString("Player1 Name", playerName);
}

function OnGUI () { 
    if (GUI.Button (Rect (10,10,100,20), "Instllningar")) 
        showMoreGui = true; 

    if (showMoreGui) { 
        GUI.Box (Rect (10, 40,500,500), ""); 
        GUI.Label (Rect (20, 50, 100, 20), "Spelare #1 - ");
        playerName = GUI.TextField (Rect (90, 50, 100, 20), playerName);

        if (GUI.Button (Rect (400, 510,100,20), "Stng")) 
            showMoreGui = false; 
    }
} 

You aren't passing the same variable to the textfield as you get returned.

namevar1 = GUI.TextField (..., name1); // See that you use different variables?

Also, it is probably better to make load/save in OnEnable and OnDisable because I heard PlayerPrefs is somewhat slow. This also makes your GUI code much cleaner. Varsgod :)

var playerName : String;

function OnEnable() {
    playerName = PlayerPrefs.GetString("Player1 Name", "Player 1");
}

function OnDisable() {
    PlayerPrefs.SetString("Player1 Name", playerName);
}

function OnGUI () { 
    GUI.Box (Rect (10, 40, 500, 500), GUIContent.none); 
    GUI.Label (Rect (20, 50, 100, 20), "Spelare #1 - ");
    playerName = GUI.TextField (Rect (90, 50, 100, 20), playerName);
}

Here isa sulotion, that works just fine for me:

var namevar1 : String;
var name1 : String;

function Update()
{
 name1 = PlayerPrefs.GetString("Player1 Name");
 namevar1 = name1;
}

function OnGUI () { 
GUI.Box (Rect (10, 40,500,500), ""); 
        GUI.Label (Rect (20, 50,100,20), "Spelare #1 - ");
        namevar1 = GUI.TextField (Rect (90, 50,100,20), ""+namevar1);

        if (GUI.changed)
    {
        PlayerPrefs.SetString("Player1 Name", namevar1);
    }
}

This will display the playerpref string "Player 1 Name", in the GUI textfield.