I want to implement in the application control by clicking on the right and left side of the screen. Put the UI Button, they have in the library UIMask, almost completely transparent with it. But almost. Whitish, you can see them. Is it possible to make them completely invisible, or how to work out pressing the right and left side of the screen?
- Pressing with your fingers? Does it mean generally anywhere on the right and left side of the screen or on the buttons on both sides? - Alexey Shimansky
- @ Alexey Shimansky I used buttons as the most obvious solution. I made 2 buttons, stretched them from the edge to the center each and everything is OK, but they are not perfectly transparent. It is necessary either to make them invisible, or to think of another way to handle clicks. Yes, with your fingers on the wheelbarrow. Yes, anywhere, the main thing is that the left and right side. - Dmitrii
2 answers
It seems to me, you can make it easier than hanging buttons on the screen. Touch should be detected anywhere on the screen, which means the logic is simple: if the touch coordinate on X is to the left of the middle of the screen, then you can do what is planned to do on the left. If the touch coordinate is on the X to the right of the middle of the screen, then you can do what is planned to be done on the right.
The programming language will be something like this:
if (Input.touchCount > 0) { var touch = Input.GetTouch(0); if (touch.position.x < Screen.width / 2) { DoLeftSideStuff(); } else if (touch.position.x > Screen.width / 2) { DoRightSideStuff(); } } Should work.
If you are looking for among several clicks, then we do a touch-through loop in the cycle:
foreach (Touch touch in Input.touches) { if (touch.position.x < Screen.width / 2) { DoLeftSideStuff(); } else if (touch.position.x > Screen.width / 2) { DoRightSideStuff(); } } ..it from sou simpl ....
Adjust the transparency of the button for all colors (Alpha) in 0/255 and you will be happy. First, use the context menu to create the button ПКМ / UI/Button in the scene. Now in the appeared button we go to the descendants and deactivate the Text . Next, go to the main object, find the Image script, click in the Color field and in the color of the bottom strip with the letter А set to 0 . Now the button is not visible, but it works. For reliability, you can also change all existing colors with Alpha = 0 in the Button script.
- Yes, I would not mind, but I found there only a choice of ready. Can you write down the steps in more detail? - Dmitrii