如何保留按钮的选定颜色,直到该组中的另一个按钮仅在Unity中选择
我遇到了一个有趣的问题。我已经在其他地方看到了一半的解决方案,但我没有遇到完整的解决方案。
因此,这是我正在开发复杂UI的游戏。主屏幕在底部导航栏中有5个按钮,单击时要调用各个屏幕。因此,当单击所选颜色的任何按钮时,都可以看到绿色,并且迄今为止一切都很好。
但是,当我单击屏幕的任何部分时,所选颜色消失了,我不希望发生这种情况。
我找到了一个解决方案在这里,它有效,但我在这里还有另一个问题。例如,在我的主页标签的主屏幕中,还有其他几个按钮,例如“购买硬币”等,当我单击这些按钮时,所选颜色会消失。当我单击屏幕的任何其他部分时,所选颜色就在那里,但是如果我在屏幕的任何按钮元素上选择选定的颜色会消失。
我尝试为按钮添加切换元件,但Unity不允许我这样做。
那么如何解决此问题?
< -------------编辑-------------->
代码是这样的:
public void OnClickBottomNavigationButton(GameObject activeScreen)//executed when any of the bottom naviagtion button is clicked
{
for (int i = 0; i < Screens.Length; i++)
{
Screens[i].SetActive(false);
}
activeScreen.SetActive(true);//after setting all to false , the required screen which is passed when the button is clicked is set to true
}
因此,此脚本附加到具有水平组件的对象,其孩子是按钮。因此,当按下任何按钮时,都会传递所需的屏幕游戏以使选择成为可能
I have ran into an interesting problem. I have seen half the solution elsewhere but I have not come across the complete solution.
So here is my game where I am developing a complex UI. The main screen has 5 buttons in the bottom navigation bar and respective screens to called when clicked. So when any of the buttons is clicked the selected colour i.e., green in my case is seen and things are fine till now.
But when I click on any part of the screen the selected colour disappears and I don't want that to happen.
I found a solution here and it works but I have another problem here. In for example the Home Screen of my Home tab there are several other buttons like "Buy Coins",etc and when I click on those buttons the selected colour disappears. When I click on any other part of the screen the selected colour is there, but if I select on any button element of the screen the selected colour disappears.
I tried adding the toggle element for the button but Unity doesn't allow me to do.
So how do I fix this problem?
<-----------EDIT--------->
The code is like this:
public void OnClickBottomNavigationButton(GameObject activeScreen)//executed when any of the bottom naviagtion button is clicked
{
for (int i = 0; i < Screens.Length; i++)
{
Screens[i].SetActive(false);
}
activeScreen.SetActive(true);//after setting all to false , the required screen which is passed when the button is clicked is set to true
}
So this script is attached to the object which has a horizontal component attached it whose children are the buttons. So when any of the buttons is pressed , the required screen Gameobject is passed to make the selection possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论