Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

InputField activating on Left Mouse Click?

Discussion in 'UGUI & TextMesh Pro' started by Trevise, Nov 17, 2014.

  1. Trevise

    Trevise

    Joined:
    Mar 31, 2014
    Posts:
    13
    I have a chat window with an InputField in order to send chat to other players. I was last on Beta 20 and had all this working perfectly. Now it's completely broken. I've narrowed the issue down to anytime I left click (Firing) in game, it activates the InputField for typing in a chat message. Nope nope nope, I only want that activated if the player presses "Submit".

    Please Help! Example code:
    Code (CSharp):
    1.  
    2. if (Input.GetButtonDown("Submit"))
    3.         {
    4.             if(Application.loadedLevelName == "magestormcath")
    5.             {
    6.                 var player = GameObject.Find(PhotonNetwork.player.name);
    7.                 if(controlsFrozen == false){
    8.                     controlsFrozen = true;
    9.                     player.GetComponent<vp_FPInput>().AllowGameplayInput = false;
    10.                     player.GetComponent<PlayerCast>().enabled = false;
    11.  
    12.                     //EventSystem.current.SetSelectedGameObject(chatInput.gameObject, null);
    13.                     chatInput.ActivateInputField();
    14.                 }
    15.                 else if(controlsFrozen == true){
    16.                     controlsFrozen = false;
    17.                     player.GetComponent<vp_FPInput>().AllowGameplayInput = true;
    18.                     player.GetComponent<PlayerCast>().enabled = true;
    19.  
    20.                     if (chatInput.text != "")
    21.                     {
    22.                         //Send Message to channel
    23.                         GuiSendsMsg();
    24.  
    25.                     }
    26.  
    27.                     chatInput.DeactivateInputField();
    28.                     //EventSystem.current.SetSelectedGameObject(null, null);
    29.                 }
    30.             }
    31.          }
     
  2. Trevise

    Trevise

    Joined:
    Mar 31, 2014
    Posts:
    13
    Anyone? Please help!
     
  3. Caio_Lib

    Caio_Lib

    Joined:
    Mar 4, 2014
    Posts:
    83
    Hi,
    I'm not sure if I understand correctly, but what I would do is change InputField's Interactable value:
    - Start InputField's Interactable:False.
    - Change to True and set focus if player press Submit button.
    - After submit the text, change to Interactable:False.
     
    Trevise likes this.
  4. Trevise

    Trevise

    Joined:
    Mar 31, 2014
    Posts:
    13
    This plus a little experimenting fixed my issue. Thank you. I should have thought of that :D