Hello.
I'm working on a simple game and I'm looking to make the controls player configurable. Is there any way to make a QWERTY keyboard pop up when a button is popped, with clickable buttons which could then be stored in a variable?
Thankyou,
Callum.
I'm still getting to grips with Unity's GUI system myself so take my suggestion with a pinch of salt, it may not be the best approach.
Your keyboard could just be a bunch of buttons and when you click on them you'd add that character onto an existing string variable. So:
var playerName : String;
function OnGUI () {
if(GUILayout.Button ("A")){
playerName = playerName + "A";
}
}
Although I can see the above as becoming quite cumbersome. Eric's suggestion of an array might be more compact?
For laying it out as a keyboard, the `BeginHorizontal/EndHorizontal` control groups sound ideal for this.
The GUI docs: http://unity3d.com/support/documentation/Manual/Game%20Interface%20Elements.html
[EDIT]
I couldn't resist trying this so the following is what I came up with. You'll need to tweak the positioning.
var playerName : String;
var alphabet : String[];
function OnGUI () {
GUILayout.BeginHorizontal();
for(var i : String in alphabet){
if(GUILayout.Button (i)){
playerName = playerName + i;
}
}
GUILayout.EndHorizontal();
GUILayout.BeginArea(Rect(0,100,200,100));
GUILayout.Label(playerName);
GUILayout.EndArea();
}
There are many ways; possibly the easiest would be to create a grid of buttons using GUI.Button/GUI.Label and an array of letters.