- Home /
high score name entry iphone
I've left high score name entry until near the end of the game as I don't quite know what to do. Maybe I read something wrong that is clouding my mind, anyway...
I have my main game game loop code that calls a HighScore () function to check if a high score has been achieved, updates the appropriate variables then goes to the Main Menu.
Currently I just have it make the player name for the score "New Score" as a placeholder.
How do I do the name entry (iPhone and Mac options)? My guess is Instantiate a new empty object that has a script calling OnGUI (something I don't use at the moment, only GUIText), that changes a nameEntry var so that I can continue my high score table updates.
I'm unsure of how to do the name entry correctly (something about OnGUI updating several times a second renewing the entry field? Is that right? maybe where I got lost).
And how do I stop the HighScore () function from continuing until I have got the name entry completed?
Answer by Eric5h5 · Sep 11, 2010 at 07:56 PM
You use coroutines for scheduling events:
function Start () {
while (true) {
yield MainMenu();
yield PlayGame();
if (score >= highScore) {
yield EnterName();
}
}
}
In practice, the functions would probably be in other scripts, so you'd have to get appropriate references first and use them. (i.e., "yield nameScript.EnterName();
")
You can use GUI.TextField for name entry. The script, which should be disabled by default so OnGUI doesn't run until needed, could be something like
private var nameEntryDone : boolean;
function EnterName () { enabled = true; // enable OnGUI function in this script nameEntryDone = false; while (!nameEntryDone) yield; enabled = false; }
function OnGUI () { // stuff with TextField if (GUILayout.Button ("Done") ) nameEntryDone = true; }
So I can stop one function until another has finished. but still in the new function, how do I stop that one until it has got a name entry? I still assume I have to create a new GameObject that contains the OnGUI that gets the name entry.
So I would have?
function HighScore () { yield NameEntry() // rest of high score code dependant on name entry }
function NameEntry () { Instantiate (nameEntryObject); ??? }
How would I fill the GUI.TextField using the iPhone$$anonymous$$eyboard? The various bits of information I have found don't seem to fit together?
Sorry, I didn't realise a reply lost the paragraph formatting
@$$anonymous$$oonjump: I added some code, which should clarify things. You can tap on a TextField which brings up the standard iPhone keyboard. Or you can make your own text entry + keyboard, which is a lot more work but can be totally customized.
Thank you Eric5h5, I understand the yield format now. The problem is still with the input. I have some code: var nameEntry = "DefaultName"; function OnGUI() { nameEntry = GUI.TextField (Rect (0, 10, Screen.width, 40), nameEntry, 31); } that I got from Unity Reference manual. This produces a box at the right time (testing on the $$anonymous$$ac version at the moment), but I cannot edit the text, even if I click on it. Plus $$anonymous$$ac / PC or iPhone I want the text entry to be active as soon as it appears. On the iPhone the keyboard should be there without the player having to tap on the TextField. Possible?
@$$anonymous$$oonjump: you might have to do your own keyboard input in that case.
Your answer
Follow this Question
Related Questions
In-app purchase "Invalid product" on Mac Store build 0 Answers
Unity iPhone is it worth it? 2 Answers
Particles are not visible on iphone 3 Answers
Any tutorials for Unity 3 to make a TEXT BASED iphone game? 3 Answers
UnityXcode ,Mach-O linker Error 2 Answers