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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Allow clicks only on specific UI elements

Discussion in 'Game Design' started by taivasltd, Apr 7, 2019.

  1. taivasltd

    taivasltd

    Joined:
    Mar 27, 2019
    Posts:
    20
    Hello,

    I have read several posts but I have not managed to make it work.

    I have a Canvas with several elements. I want to do the following:

    - Clicks should not be passed as actions in the code. Currently if I click in the canvas it seems to pass through as an action so I see some results I should not be seen.
    - Allow only specific UI elements to be clicked e.g. I have a text input field so upon click it should just allow me to type.

    Any suggestions welcome
     
  2. taivasltd

    taivasltd

    Joined:
    Mar 27, 2019
    Posts:
    20
    I think I found a workaround that seems so far to work as expected

    if(userInput == null || userInput == "")
    {
    inputField.ActivateInputField();
    return;
    }

    Quite simply if mouse is clicked (and therefore there is no string input) I simply activate the input field (therefore I can still type) and exit the function that accepts the user input. So no clicks are sent further down