Search Unity

Question related to TouchScreenKeyboard.done in android application in C#

Discussion in 'Immediate Mode GUI (IMGUI)' started by g_p_programmer, Aug 19, 2014.

  1. g_p_programmer

    g_p_programmer

    Joined:
    Feb 19, 2014
    Posts:
    12
    Hello,

    I have the following code in C# for Android appication.
    When I click on a button the keyboard appears on the screen.
    Everything is fine!
    When I click on the "OK/Enter" button, the
    Code (CSharp):
    1. keyboard.done
    becomes true
    and the "NextScene" is loaded, ok wth that.

    I noticed that when I click in another area on the screen and not on the "OK/Enter" button
    of the keyboard, the
    Code (CSharp):
    1. keyboard.done
    becomes true again and the next Scene is loaded!

    I wouldn't like that to happen.
    If you run the following code, you 'll see that if you click in any area on the screen the
    Code (CSharp):
    1. keyboard.done
    becomes true and the "NextScene" is loaded.
    Why does that happen?

    What can I do in order to fix that?

    Thanks, in advance

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Search : MonoBehaviour {
    5.     public string inputURL = "http://www.unity3d.com";
    6.     private TouchScreenKeyboard keyboard;
    7.     private bool openedKeyboard = false;
    8.    
    9.     private int touchedScreen = 0;
    10.     void OnGUI() {
    11.  
    12.                 if (GUI.Button (new Rect (0, 500, 200, 200), inputURL)) {
    13.                        
    14.                             keyboard = TouchScreenKeyboard.Open (inputURL);
    15.                             openedKeyboard = true;
    16.                             }
    17.                 if (openedKeyboard) {
    18.                     if (keyboard.active) {
    19.                        
    20.                         inputURL = keyboard.text;
    21.                         GUI.Label (new Rect (0, 0, 100, 100), inputURL);
    22.                        
    23.                         }
    24.                     if (keyboard.wasCanceled) {
    25.                         openedKeyboard = false;
    26.  
    27.                     }
    28.                     else if (keyboard.done) {      //If I click on the rest of the screen, the keyboard.done is true
    29.                                                                  // and the NextScene is loaded!!! I don't want that to happen!!!
    30.                             openedKeyboard = false;
    31.                             Application.LoadLevel ("NextScene");
    32.                     }
    33.                 }
    34.     }
    35. }
     
  2. g_p_programmer

    g_p_programmer

    Joined:
    Feb 19, 2014
    Posts:
    12
    Can someone reply to the question because it is really urgent?

    Thanks