- Home /
Is there any way to make a virtual keyboard (QWERTY)
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.
Answer by straydogstrut · May 16, 2010 at 05:44 PM
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(); }
Answer by Eric5h5 · May 16, 2010 at 05:36 PM
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.
Your answer
Follow this Question
Related Questions
Changing the keyboard type used on a GUI.TextField 0 Answers
GUI Texture Problem 3 Answers
Keyboard control of GUI 1 Answer
How do create iOS virtual keyboard input for raw ASCII control characters ? 0 Answers