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

How to check if I touch in any place to disable the description panel [Mobile/Android]

Discussion in 'Scripting' started by Kalita2127, Oct 18, 2016.

  1. Kalita2127

    Kalita2127

    Joined:
    Dec 6, 2014
    Posts:
    244
    Hi guys I'm having trouble when I touch in any place to disable the description like the image below.

    https://snag.gy/CQFVKL.jpg
    I've did some googling but no result or maybe my keyword is sucks. Anyone know how to solve this ? Thank you.
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Okay, so you want "any touch" to disable that panel? There are a couple of different ways to do this, but I think you should consider WHY you want it to disappear, and the exact circumstances in which you want it to disappear. My guess is that you're actually "selecting" items in the inventory, and when they are selected, the panel is there to describe it, but when they are deselected, you want the panel to go away. In that case, you'll need to call a "select" and "deselect" function in a controller, not manipulate the panel directly. Just keep that in mind.

    How this is accomplished depends heavily on exactly what you want to happen- do you want the panel to go away when you click the description panel itself, or just any empty item in the inventory, when you click the same item again, when you click the screen outside of the inventory panel, and how about the other links on the page?

    If the answer is "when I click anywhere, period", well, you'll just want to react to the touch input directly, and then call the "deselect item" function from there. This is really simple and doesn't require anything special- it also doesn't block any selections you're making when you click the screen, so the action is concurrent to whatever else is going on.

    If there are specific places on the screen where you want a touch to make the panel disappear, then there are two big methods. First, you can use a variation on the above method where you additionally specify screen percentages (or pixels) directly for the input position- for instance "between 10% and 90% of the screen width, and 5% and 20% of the screen height". This allows you to choose screen "regions" that will make the panel disappear if you click in them, but not stop the input from passing through and interacting with other UI and objects in the scene. Second, you can use those areas sort of like buttons, adding a component to it that makes it react to the input action. You can do that with the EventTrigger component or writing your own script to implement the interfaces you want.

    The problem with the second option is that it intercepts the input commands, so if a "button" on the screen is pressed, then what's behind it won't get pressed- if you're covering a large area on the screen, you can make the image completely transparent so it can't be seen, but you'll need to remember to disable it when it's activated and re-enable it when the panel appears again. You'll also have to be careful not to block other actions that you want to perform- you can do this by placing the image behind all of the over UI layers, but then any area with a different UI graphic will block the input and not make the description panel disappear (clicking inside the inventory window, for instance). You also need to use raycast layers on your "click objects in the scene" input controller so that it doesn't interact with that UI layer.

    Anyways, just some ideas. It really comes down to what exactly you want (click anywhere, click in regions, allowing the input to "pass through", or intercepting it so that it doesn't interact with what's behind, etc...).
     
    DroidifyDevs likes this.
  3. Kalita2127

    Kalita2127

    Joined:
    Dec 6, 2014
    Posts:
    244
    I just feel like the player will expect when he touched anywhere the description will be empty.
    So you mean I have to create an empty game object contains the script that control the panel ?
    When I rethink about it and consider me as the player, maybe I expect that when I touch anywhere on the screen the description will disappear or the second is the inventory panel will slide down. (By the way the inventory panel do slide down or slide up when you press the inventory icon)
    Actually I want to make the description disappear if the player touched anywhere outside the inventory panel.
    Sorry I can't clearly understand what you want to explain here. My english is not really good though.

    What it's mean by 'it incercepts the input command' ?

    And the sentence 'so if a "button" on the screen is pressed, then what's behind it won't get pressed' do you mean the background ?

    And then the sentence ' You'll also have to be careful not to block other actions that you want to perform- you can do this by placing the image behind all of the over UI layers' what it does exactly when I placed the image behind the UI layers ?

    And the sentence 'You also need to use raycast layers on your "click objects in the scene" input controller so that it doesn't interact with that UI layer' so the input will ignore the UI layer ?