I basically just want to know how I would go about detecting if the user is touching either the left or right side of the screen? I’m assuming I would use Input.touches, but I’m not sure where to go from there. Thanks in advance for any help!
After a little bit of research into the Touch class I’ve answered my own question. A simple script to detect touching the left or right side of the screen would be:
if (Input.touchCount == 1)
{
var touch = Input.touches[0];
if (touch.position.x < Screen.width/2)
{
DoLeftSideStuff();
}
else if (touch.position.x > Screen.width/2)
{
DoRightSideStuff();
}
}
When you don’t want have multiply clicking when finger touch screen here is code:
void Update () {
if (Input.touchCount > 0)
{
var touch = Input.GetTouch(0);
if (touch.position.x < Screen.width/2)
{
if(Input.GetTouch(0).phase == TouchPhase.Began)
{
Debug.Log("Left click");
}
}
else if (touch.position.x > Screen.width/2)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
Debug.Log("Right click");
}
}
}
}