Hi! Im running into a little problem I am creating a game and one of the components is that you have to enter text that is going to be showed in a Gui.Label. Here is how i do that:
void OnGUI() {
GUI.Label(new Rect(10, 10, 100, 20), stringToEdit);
}
void Update(){
if(GM.Lockin&& !(Input.GetKeyDown(KeyCode.Backspace))){
stringToEdit = stringToEdit + Input.inputString;
}
}
The lockin variable is set when the user left clicks so that if they press wasd they wont be walking. Now if they make a mistake then I want them to be able to remove some of the string so here is what i have for that.
if(Input.GetKeyDown (KeyCode.Backspace)){
if(stringToEdit.Length==1){
stringToEdit=string.Empty;
}
else stringToEdit=stringToEdit.Remove(stringToEdit.Length-2);
}
The reason i have to subtract by two is because the backspace is being entered into the string as well so I have to remove that as well. I have the if stringToEdit==1 because i will get an error that im subtracting too much. I am displaying stringToEdit.Length in the console and I see that it does change to 0 after the string.Empty is called but something keeps adding something to the string after that happens. I have to compare this to something later on so it messes up the comparison. even though the text will be exactly the same the stringToEdit will have an extra length then it should. Any ideas?Ive been stuck on this for quite some time. Anything can help really. Thanks!
~Dezert99~