x


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?

more ▼

asked Sep 11 '10 at 04:34 PM

Moonjump gravatar image

Moonjump
13 2 2 9

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
}
more ▼

answered Sep 11 '10 at 07:56 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

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 iPhoneKeyboard? The various bits of information I have found don't seem to fit together?

Sep 11 '10 at 08:33 PM Moonjump

Sorry, I didn't realise a reply lost the paragraph formatting

Sep 11 '10 at 08:34 PM Moonjump

@Moonjump: 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.

Sep 11 '10 at 09:10 PM Eric5h5

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 Mac version at the moment), but I cannot edit the text, even if I click on it. Plus Mac / 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?

Sep 11 '10 at 09:30 PM Moonjump

@Moonjump: you might have to do your own keyboard input in that case.

Sep 11 '10 at 09:50 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2014
x567
x346
x2

asked: Sep 11 '10 at 04:34 PM

Seen: 1688 times

Last Updated: Sep 11 '10 at 05:48 PM