Hi,
I’ve been messing around with the TextController, and I’ve come up with a simple text editor where you can type numbers and spaces. I wondered that my program basically contains a lot of repeated code, but I don’t see a way to simplify it! This is my Update() method:
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
text.text += " ";
} if (Input.GetKeyDown (KeyCode.Alpha1)) {
text.text += "1";
} if (Input.GetKeyDown (KeyCode.Alpha2)) {
text.text += "2";
} if (Input.GetKeyDown (KeyCode.Alpha3)) {
text.text += "3";
} if (Input.GetKeyDown (KeyCode.Alpha4)) {
text.text += "4";
} if (Input.GetKeyDown (KeyCode.Alpha5)) {
text.text += "5";
} if (Input.GetKeyDown (KeyCode.Alpha6)) {
text.text += "6";
} if (Input.GetKeyDown (KeyCode.Alpha7)) {
text.text += "7";
} if (Input.GetKeyDown (KeyCode.Alpha8)) {
text.text += "8";
} if (Input.GetKeyDown (KeyCode.Alpha9)) {
text.text += "9";
} if (Input.GetKeyDown (KeyCode.Alpha0)) {
text.text += "0";
}
I would appreciate any input to simplify this piece of code, it doesn’t affect the speed of the program much, but just for organizing and learning reasons ;).
Thanks in advance!!!