Using OnGUI to change text in 3D text object.

I have a GUI set up with textfields and want to be able to get the text from there and set the 3D text as what is entered. What is the simplest way to accomplish this? I am using c#.

public string stringToEdit = “Hello World”;
public TextMesh textmesh;
void OnGUI() {
stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 25);
textmesh.text = stringToEdit;
}