Problem with Load Level Script

Hi guys,I need some help…What i need is when player type in GUI box number 3 and press enter then load new level

Thanks for any help :smiley:

Here is my script

using UnityEngine;
using System.Collections;

public class NumberScript : MonoBehaviour 
{

		string stringToWrite = "";
		
		void  OnGUI ()
		{
		stringToWrite = GUI.TextArea ( new Rect(570, 450, 100, 20), stringToWrite, 3000);
		}
		
	void Update()
	{
		if(Input.GetKeyDown("3"))
		{
			
			if (Input.GetKeyDown(KeyCode.KeypadEnter))
			{
				Application.LoadLevel(10);
			}
		} 
		
	}
}

The TextArea will capture the keyboard input when someone is typing so Input.GetKeyDown will return false. In order to detect that a player has typed “3” and pressed enter, you could test the stringToWrite variable for those keystrokes.

The Equals method can be used if you want to change level when the text area contains only “3” after enter has been pressed…

if (stringToWrite.Equals("3

")) {
Application.LoadLevel(10);
}

The EndsWith method can be used if you intend to allow text to be continuously entered and want to detect when “3” and enter were recently pressed…

if (stringToWrite.EndsWith("3

")) {
Application.LoadLevel(10);
}