Why do my Unity Buttons need multiple taps to fina

2019-04-29 22:42发布

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.

enter image description here

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.

2条回答
Deceive 欺骗
2楼-- · 2019-04-29 23:28

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.

查看更多
Anthone
3楼-- · 2019-04-29 23:29

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.

查看更多
登录 后发表回答