Why do my Unity Buttons need multiple taps to finally work?

淺唱寂寞╮ 提交于 2019-12-22 07:48:19

问题


As the title suggests, I have a screen with two canvases. Both literally a copy of each other, but simply having a different layout for my Portrait and Landscape orientations. As and when the orientation changes, I disable to appropriate Gameobject containing the Canvas.

Now, I've never had any problems with the other buttons from the previous canvas open, but I've got this problem where my active canvas needs multiple taps on the same button to finally WORK.

Should I be doing something differently?

EDIT: There's no problem when I test it on Unity Editor. Only when it goes onto an Android or iOS device.

Please keep in mind that it DOES work. It just that it takes endless tries to do so.


回答1:


Usually the kind of click that sometimes-works-sometimes-doesn't is caused by two colliders at the same distance from the camera.

Try changing Z-position of a button/canvas to see if this is the case.

Ray casting, which is quite likely used under the hood for canvas clicks, is only sending the onMouseDown event closest resembles colliders.

Also on the Canvas, if its on Screen Space - Camera adjust the Order in Layer so that no two canvases are on the same layer.

If there are two at the same layer, it has to choose either one of them. It seems that, in this case, unity chooses any one randomly.




回答2:


I had the same problem. In my case, the reason was that I had both: TouchInputModule and StandaloneInputModule on the same gameObject. Just removing one of inputs solves my problem.



来源:https://stackoverflow.com/questions/30659380/why-do-my-unity-buttons-need-multiple-taps-to-finally-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!