Input name from i phone keyboard

HI,

i am new to the unity IOS. i was trying to input the player name from the iPhone keyboard but as i click on the enter name button(which is a GUI texture) the keyboard appears but before i could enter anything the keyboard disappears and the next scene is loaded.

i am using the following code

var btnTexture : Texture;
private var keyboard : iPhoneKeyboard;
var tempString : String = "";
var playerName : String = "";
function OnGUI () 
{
	
	if (!btnTexture) 
	{
	Debug.LogError("Please assign a texture on the inspector");
	return;
	}
	
	if (GUI.Button (Rect (45*(Screen.width)/100,40*(Screen.height)/100, 130, 50), "ENTER NAME:"))
	{
		// Open Keyboard
		keyboard = iPhoneKeyboard.Open(tempString, iPhoneKeyboardType.Default, false, false, false, false, "Enter Your Name Here");
		
	}	

	// While keyboard is active, take keyboard input:
	if (keyboard)
	{
    	        playerName = keyboard.text;
				Application.LoadLevel(2);  // scene 2 is the next level which i want to load after saving the name	
	}
}

would be really pleased if i could get some help …

I don’t have iOS kit, but I think your coding is wrong. You checking if the keyboard is open, and if so, setting the playername to keyboard.text, which makes sense, but in the same if statement, you have Application.LoadLevel(2);, which is running as soon as the keyboard is opened. Just add another button to the screen (like OK, or GO, or Submit, or something) that loads the level, instead of just when the keyboard is opened or closed. (I bet you it will work except for loading the new level if you comment out the application.loadlevel.)

Hope this helps you some. Like I said, I don’t have a license for iOS, so I don’t understand how the keyboard event works, but being in the same if statement that interprets the keyboard inputs as they are being pressed (the only way I can personally see that statement working in general) then it will instantly load the level after the keyboard is opened and waiting for input.

O-o Let me know if that works or not.

hmm…lemme check dis out…

hmm… i worked perfect …i took a submit button and placed the application.load level in that and it worked…some silly mistakes can eat up a lot of time …thanks

Sometimes it just takes some fresh eyes. :slight_smile: Glad I could help.