Quantcast
Channel: Latest Questions by orcinusdev
Viewing all articles
Browse latest Browse all 26

Divide screen into two touch buttons

$
0
0
Hey! I'm trying to make a object rotate based on if the user touches the left side of the screen or the right side of the screen. If the user presses the left side of the screen before releasing the right side of the screen (or the other way around), the new input should be the one that object rotates after. And when the user is not touching the screen the rotation should be zero. I have currently come up to this code which doesn't work at all. void Update() { int i = 0; while (i < Input.touchCount) { if (Input.GetTouch(i).phase == TouchPhase.Began) { if(Input.GetTouch(i).position.x < 0) playerMovementDirectionFromInput = -1; if(Input.GetTouch(i).position.x > 0) playerMovementDirectionFromInput = 1; } ++i; } playerMovementDirectionFromInput = 0; } and the player is rotating by a transform.Rotate code where playerMovementDirectionFromInput is multiplied to. A tried using the void OnMouseDown() with two colliders which works but this method falls when the user is pressing the other button before releasing the first one. So i think the only way of doing this is with Input.GetTouch. What is wrong? (I'm new into using touch inputs so feel free to treat me like a fool)

Viewing all articles
Browse latest Browse all 26

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>