The TouchScreenKeyboard just doesn’t want to work.
It opens up, you can put in the string but as soon as you click done, it’s gone- like it was never there. You can do this everyday with any string doesn’t work.
I am just using two simple lines of code
// declaration and stuff
//psuedocode
private string x1;
private TouchScreenKeyboard numpad = null;
private string x1;
public tk2dTextMesh textfield;
void Update () {
if (Input.touchCount > 0) {
Ray r0 = Camera.main.ScreenPointToRay (new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y));
RaycastHit hit;
if(Physics.Raycast(r0, out hit))
{
Debug.Log ("Enter The Number");
if(hit.collider.name == "NumInput")
{
numpad = TouchScreenKeyboard.Open (x1, TouchScreenKeyboardType.NumberPad);
numpad.active = true;
}
}
}
if (numpad != null) {
textfield.text = x1;
}
}
I have wasted 10 hours on this plus I have to make apk(s) everytime to test the code out…
In your case, when you click “Ok”, your mobile keboard is gone, but variable “numpad” is not null. Maybe, check status this variable. But you can use visible/invisible keyboard method, try:
//Add variable for detection
private bool isFirst = false;
void Start() {
x1 = ""; //initialization string, whitout line your variable is null
}
void Update () {
if (Input.touchCount > 0) {
Ray r0 = Camera.main.ScreenPointToRay (new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y));
RaycastHit hit;
if(Physics.Raycast(r0, out hit)) {
Debug.Log ("Enter The Number");
if(hit.collider.name == "NumInput") {
numpad = TouchScreenKeyboard.Open (x1, TouchScreenKeyboardType.NumberPad);
numpad.active = true;
//Change variable for activation
isFirst = true;
}
}
}
//Change end condition (or, maybe, play with it parametr)
if (isFirst && !TouchScreenKeyboard.visible) {
textfield.text = x1;
isFirst = false;
}
}