It's reading letters from Input.inputString. So all we have to do is provide our own alternate input source.
public class CustomInput : MonoBehaviour {
string inputThisFrame = "";
// Call this method from your on-screen buttons.
public void Type(string text) {
inputThisFrame += text;
}
// Expose text the same way Input does.
public string inputString {
get {
if(inputThisFrame != "")
return inputThisFrame;
// Fall back on built-in input.
return Input.inputString;
}
}
// At the end of the frame, clear the buffer
// so we start from scratch next frame.
void LateUpdate() {
inputThisFrame = "";
}
}
Now you can:
- Place an instance of CustomInput in your scene
Place an instance of CustomInput in your scene
- Wire up your on-screen buttons to report their typing to the CustomInput instance
Wire up your on-screen buttons to report their typing to the CustomInput instance
- Modify WordInput so it takes an instance of CustomInput and asks for its
inputStringinstead of the built-in Input.Modify WordInput so it takes an instance of CustomInput and asks for its
inputStringinstead of the built-in Input.The fallback we added above ensures the regular keyboard still works, when presentz which helps with testing.
The fallback we added above ensures the regular keyboard still works, when presentz which helps with testing.