Dividing the screen into two inputs is was enough with Screen.width / 2, but now I want to try a game where there are 3 places for input: top, middle, and bottom of the screen, all of equal sizes. I know this can be achieved with buttons, but it seems that using “Input.GetMouseButtonDown” is much faster than what buttons can do. And the accuracy of presses is important in this game for music/rhythm reasons.
Hello tablazonsimon
I would go in this way:
public class Controls : MonoBehaviour
{
int splittedScreen = Screen.height / 3;
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
if (Input.mousePosition.y >= 2 * splittedScreen)
{
Debug.Log("Top");
}
if (Input.mousePosition.y >= splittedScreen &&
Input.mousePosition.y < 2 * splittedScreen)
{
Debug.Log("Middle");
}
if (Input.mousePosition.y < splittedScreen)
{
Debug.Log("Down");
}
}
}
}
It is quite simple, you save the value of the Screen Height divided by 3 and with the if statements you check where the mouse is when we tap on the screen.
Hope it helps!