- Home /
Android Pause conflicting with action
I made a pause button for my simple game which is in the top right corner nothing special. The problem is that my controls on android are if you click on right side of screen you move right and the opposite.
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch (0);
float middle = Screen.width / 2;
if (touch.position.x < middle && touch.phase == TouchPhase.Began) {
//moveLeft;
player.transform.position = new Vector3 (player.position.x-3, player.position.y, player.position.z);
}
if (touch.position.x > middle && touch.phase == TouchPhase.Began) {
//moveRight;
player.transform.position = new Vector3 (player.position.x+3, player.position.y, player.position.z);
}
}
So whenever I click the pause button it pauses but it also moves the player to the right. How do I stop that from happening. (I know I could make left and right separate buttons but I really like the way the controls are at the moment and do not want to change them).
Answer by Matthew_Ostil · Nov 21, 2018 at 06:46 PM
There are three solutions I can think of, all doable and really up to your preference:
Include a y-position zone (a min-y and max-y area the tap must be inside) and have it not include the top UI area. Realistically, most player's wouldn't be tapping the tops of their phones to move the character anyway since that would be a bit uncomfortable?
Change your controls to use invisible buttons as hit areas (or real buttons if the UI allows for it)
Do a raycast check when you tap to see if you're not first hitting a certain layer (such as a UI layer)