Im going to make a custom number keypad in unity. I'm wondering how can i make it by simple way with much short and clean code. Below code is just for explaining my idea.
var str=""; //This is the result string that i have to send to host
var key0 = document.getElementById('key0').value;
var key1 = document.getElementById('key1').value;
var key2 = document.getElementById('key2').value;
var key3 = document.getElementById('key3').value;
... so on
key0.onclick= function() { //button click events
str += "0";
}
key1.onclick= function() {
str += "1";
}
key2.onclick= function() {
str += "2";
}
key3.onclick= function() {
str += "2";
}
... so on
function getStr() {
return str;
}
I know this code is rubbish but i'm just thinking like this way; event process. But if i make the each buttons as gameobjects then, they all have the colliders right? and the colliders aware of when they touched. so i also thought in this way.
var array = [key0, key1, key2, key3, ...]; //The list consisted of the gameobjects
foreach (array as arr) {
arr.collider.onTouched = function() { //Assign the events to each gameobject's collider
str += arr.getNumber(); // custom function 'getNumber' to attach the number to string
}
}
I'm just drawing the code. oh and the important thing is returning result string when i push the enter key. so i'm thinking how can i make the get;set function in C# code in unity. Do i manage this works in onUpdate function?
Please let me know what is the best idea to handle this process.Thank you.