Hello guys I’m running into an issue. I have a string that I want to lose a letter if backspace is pressed. Here is my code.
if(Input.GetKeyDown (KeyCode.Backspace)){
stringToEdit= stringToEdit.Substring(0,stringToEdit.Length-1);
Debug.Log (“Backspace is pressed”);
}
This should work and I know it has something to do with the stringToEdit.Lenght. If i put in my own value for the length it would work just fine. Does anyone know why this is happening?
Incase you need to see the entire code here it is.
using UnityEngine;
using System.Collections;
public class Gui : MonoBehaviour {
public string stringToEdit = “”;
public GameManager GM=null;
void OnGUI() {
GUI.Label(new Rect(10, 10, 100, 20), stringToEdit);
}
void Update(){
if(GM.Lockin){
stringToEdit = stringToEdit + Input.inputString;
Debug.Log (stringToEdit);
}
if(Input.GetKeyDown (KeyCode.Backspace)){
stringToEdit= stringToEdit.Substring(0,stringToEdit.Length-1);
Debug.Log (“Backspace is pressed”);
}
}
}
Oh and also im running into a problem where when im checking the value of what the user entered in stringToEdit it wont see the answer as correct if the user enters lets say bob. But if i hard code the value for stringToEdit as bob it will work jut fine. Any ideas on why that’s happening as well?
void OnTriggerStay(Collider other){
Debug.Log (element+“User is in trigger”);
if (mygui.stringToEdit == answer) {
answer.text = “Correct!”;
Debug.Log (“Correct”);
}
}