首页 > 解决方案 > 如何检测按钮是否没有被点击/如果没有点击如何让某些东西消失

问题描述

嗨,我正在制作卡片清单,其中有 4 张选定的卡片和可供选择的卡片网格。按下卡时,我会弹出一个按钮,您可以按该按钮来选择卡,但我的问题是我不知道如何使该按钮消失。

我希望在按下一张卡时显示一个选择按钮,然后按下另一个将使其消失,或者按其他任何按钮将使其消失。但我不知道该怎么做。

下拉 ui 模板有这个内置的客栈,当单击下拉选项时,会显示选项,当单击其他任何内容时,它会消失,我想要那个。

编辑:为了进一步澄清,我有 2 个按钮,1 个使另一个可见,当单击按钮本身以外的任何其他内容时,另一个将消失。这就是我所拥有的

任何想法在互联网上随机奇妙的陌生人

标签: c#unity3d

解决方案


As I misunderstood your problem the first time, I'll write it the second time.

I think this is really simple to solve, so basically create a huge and transparent button which will detect all of the clicks besides from the cards and buttons.

So my solution is:

  1. Create a button called for example "Background" and set its scale to an enormous values like 1000 to cover the whole screen all time.
  2. Set all of the button's colors (Normal Color, Highlighted, Pressed, etc.) to transparent - basically set the Alpha value to 0
  3. The button has to be above all of the other buttons in the Hierarchy of Canvas (or however you called it) in order to work as a background and not cover up other buttons.
  4. Detect the clicks on the "Background", which will just hide the "Select" and the "Info" button.

I hope this time it will work.


推荐阅读