|
Hey, i've got some trouble as im trying to display a Playerpref string in a gui textfield, heres the code:
Made lines that ain't relevant right now comments. Thanks in advance! Current code:
(comments are locked)
|
|
Here isa sulotion, that works just fine for me:
This will display the playerpref string "Player 1 Name", in the GUI textfield.
(comments are locked)
|
|
You aren't passing the same variable to the textfield as you get returned.
Also, it is probably better to make load/save in OnEnable and OnDisable because I heard PlayerPrefs is somewhat slow. This also makes your GUI code much cleaner. Varsgod :) I'm still trying to get this working for 18 objects that should do the same (18 textfields). Just woundering what the second var at the "playerName = PlayerPrefs.GetString("Player1 Name", "Player 1");" does? :)
Mar 28 '11 at 03:02 PM
Tommy
The second variable "Player 1" is the default value returned if there was no value to start with. For example, playing the game for the first time. It's just a convenience so you don't have to write code such as if !exists player1, set player1 "Player 1". If you are going to repeat input like that I'd suggest you make a function that handles this automatically. Store each player value in a new class for easier variable management.
Mar 28 '11 at 03:05 PM
Statement ♦♦
I suggest you make helper functions like LabelTextField which accept two parameters (except rect). Like so: LabelTextField(Rect (10, 40, 500, 500), "Spelare #1", player1.name);
Mar 28 '11 at 03:07 PM
Statement ♦♦
And also make a higher level function like PlayerGUI(Rect(.....), player1) which in turn make use of LabelTextField, which you also have to code for yourself. Much cleaner than having a ton of controls right after each other :)
Mar 28 '11 at 03:08 PM
Statement ♦♦
To group gui items make use of GUI.BeginGroup and GUI.EndGroup. That way you can work with relative position. There's also GUILayout so you don't have to deal a lot with rect sizes. Either way works of course and as long you get the job done any way is the right way :)
Mar 28 '11 at 03:10 PM
Statement ♦♦
(comments are locked)
|
