GUI Not updating

Hey all, I have had a look around and can not find a perfewct answer to my question. I am playing around with Unity again and think it is an amazing Game Engine. I am having a go at it with Javascript, I know C# but want to test my Javascript which is a little shoddy compared to other languages.

Anyhow, I want to use this script which I found when trying to find out an answer to my problem. However it is not updating the GUI at all! It just does nothing. I am using the standard controller which is included in the 2D tutorial.

var stringToEdit = "Player1"; 
var userHasHitOk : boolean = false;

function Update() { 
    	if(Input.GetKeyDown("enter")) { userHasHitOk = true; }
    function OnGUI () {
    	if (userHasHitOk)
    	    GUI.Label (Rect (10, 10, 100, 30), "Hello " + stringToEdit);
    	GUI.Label (Rect (10, 10, 100, 30), "Enter Name:");
    	stringToEdit = GUI.TextField (Rect (90, 10, 200, 25), stringToEdit, 40);

This code is in the CameraFocus.js file but it just does not update at all. It displays the GUI but no update.

Hope someone can help,

Thank you

The problem here is that you are waiting for the user to press ‘Enter’ after they type some text into a text field. Unfortunately, the default behaviour for such fields is that they prevent normal Input.keyPress-type functions from working, so that the text field can be entered without the player accidentally using their input keys!

Recently the boolean value ‘Input.eatKeyPressOnTextFieldFocus’ has been added, which lets you override that behaviour. Just set

Input.eatKeyPressOnTextFieldFocus = false;

at the top of your script, and you’ll be good to go!