3d text to trigger mobile keyboard

I want to use 3d text as the button to trigger open mobile keyboard. Currently what I do is having a box as the collider as the child to the 3d text and change size accordingly to the length of the 3d text. Whenever you touch the box collider, it will trigger a GUI.Textfield and when you tap on the GUI.Textfield, the mobile keyboard will be launch for you to input. here’s my code:

void OnGUI () {
		if(inEditMode) {
			GUI.SetNextControlName ("hiddenTextField"); //Prepare a Control Name so we can focus the TextField
			GUI.FocusControl ("hiddenTextField");     //Focus the TextField
			guiString = GUI.TextField (new Rect (90, 100, 200, 25), guiString, 25);  //Display a TextField
			textComponent.text = guiString;
		}

                if (Input.GetMouseButtonDown(0)) { 
			ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			if(Physics.Raycast(ray,out hit))
			{
					if(hit.transform== boxcollider.transform) {
					print("touched!!");
						inEditMode = true;
					}  else {
						inEditMode = false;
					}
			}
		}
}

But I want to make do without tapping on the GUI.Textfield. Is it possible?

I tried an alternative method:

if (Input.GetMouseButtonDown(0)) { 
			ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			if(Physics.Raycast(ray,out hit))
			{
					if(hit.transform== boxcollider.transform) {
					TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true, true);///<-- Added this line!!!
						inEditMode = true;
					}  else {
						inEditMode = false;
					}
			}
		}

That TouchScreenKeyboard.Open did trigger a keyboard but do not sync with GUI.Textfield. but if you tap on GUI.Textfield at this moment, another keyboard will open and that will sync. At this point, you have 2 layers of keyboard.

Any suggestions will be good.

You need to re-read this, after one pass i can see your error. Read the example they give. And see what the keyboard function is actually doing. It returns a type touchscreenkeyboard, which has variables you can access such as text(being the text typed into the keyboard) as you can see in the unity example you need to update you textfields text to relect that of the keyboards text.

Thanks to KRanges’ advise, Now I figure out:

        ///define keyboard and important variables

        private TouchScreenKeyboard keyboard;//<--- add this line
	private bool inEditMode  = false;
	private string guiString;

      /// more codes here...

void OnGUI () {
       if(inEditMode) {
         GUI.SetNextControlName ("hiddenTextField"); //Prepare a Control Name so we can focus the TextField
         GUI.FocusControl ("hiddenTextField");     //Focus the TextField
         guiString = GUI.TextField (new Rect (90, 100, 200, 25), guiString, 25);  //Display a TextField
         guiString = keyboard.text; //<-- add this line
         textComponent.text = guiString;
       }
 
                if (Input.GetMouseButtonDown(0)) { 
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray,out hit))
         {
              if(hit.transform== boxcollider.transform) {
              print("touched!!");
              keyboard = TouchScreenKeyboard.Open(guiString, TouchScreenKeyboardType.URL);//<--- add this line
                 inEditMode = true;
              }  else {
                 inEditMode = false;
              }
         }
       }
}

One thing though, if you do this, the normal keyboard is not working anymore.