Hi I am trying to make a typing game that is based on comparing strings and this is the script for the first word "The". Everything works except that when I use Event.Current.isKey and display it on my string it wont let me use the backspace to delete the letter already typed. Please Help.
var theString : String = "";
var theSkin : GUISkin;
var The : GameObject;
function OnGUI() {
GUI.skin = theSkin;
GUI.TextField(Rect(100, 200, 200, 20), theString, 3);
Word1();
}
static var lastChar : String = "";
function Word1() {
if (Event.current.isKey) {
if (lastChar != Event.current.character) {
lastChar = Event.current.character.ToString();
switch (lastChar) {
case ("a"): theString += "a"; break;
case ("b"): theString += "b"; break;
case ("c"): theString += "c"; break;
case ("d"): theString += "d"; break;
case ("e"): theString += "e"; break;
case ("f"): theString += "f"; break;
case ("g"): theString += "g"; break;
case ("h"): theString += "h"; break;
case ("i"): theString += "i"; break;
case ("j"): theString += "j"; break;
case ("k"): theString += "k"; break;
case ("l"): theString += "l"; break;
case ("m"): theString += "m"; break;
case ("n"): theString += "n"; break;
case ("o"): theString += "o"; break;
case ("p"): theString += "p"; break;
case ("q"): theString += "q"; break;
case ("r"): theString += "r"; break;
case ("s"): theString += "s"; break;
case ("t"): theString += "t"; break;
case ("u"): theString += "u"; break;
case ("v"): theString += "v"; break;
case ("w"): theString += "w"; break;
case ("x"): theString += "x"; break;
case ("y"): theString += "y"; break;
case ("z"): theString += "z"; break;
case ("A"): theString += "A"; break;
case ("B"): theString += "B"; break;
case ("C"): theString += "C"; break;
case ("D"): theString += "D"; break;
case ("E"): theString += "E"; break;
case ("F"): theString += "F"; break;
case ("G"): theString += "G"; break;
case ("H"): theString += "H"; break;
case ("I"): theString += "I"; break;
case ("J"): theString += "J"; break;
case ("K"): theString += "K"; break;
case ("L"): theString += "L"; break;
case ("M"): theString += "M"; break;
case ("N"): theString += "N"; break;
case ("O"): theString += "O"; break;
case ("P"): theString += "P"; break;
case ("Q"): theString += "Q"; break;
case ("R"): theString += "R"; break;
case ("S"): theString += "S"; break;
case ("T"): theString += "T"; break;
case ("U"): theString += "U"; break;
case ("V"): theString += "V"; break;
case ("W"): theString += "W"; break;
case ("X"): theString += "X"; break;
case ("Y"): theString += "Y"; break;
case ("Z"): theString += "Z"; break;
default: break;
}
var compString : String = "The";
var compString2 : String = "a";
if (theString == compString) {
The.GetComponent("TheGreen").enabled = true;
}
if (theString == compString2) {
The.GetComponent("TheRed").enabled = true;
}
if (Input.GetKeyDown("backspace")){
// this is where I would like to delete one character at a time but dont know what script to use
The.GetComponent("TheClear").enabled = true;
}
}
}
}
Wait, are you asking how to delete a character, or are you just saying that your current method isn't working? (Because you said it 'won't let you' delete a character, my assumption was that you have some code in place for this already, but that it's not working as you expect.)
– j_y_k