foreach (Touch touch in Input.touches){
if(leftBounds.Contains(touch.position)){
GameManager.left_touch_count ++;
}
if(rightBounds.Contains(touch.position)){
GameManager.right_touch_count ++;
}
}
My code works if you have your left thumb held down on the left side of the screen, the count goes up, but if you keep it held down and then press your right thumb on the screen, the right count doesn’t go up. I thought if you used touch input it could detect more than one touch at a time? Am I doing something wrong?
Hey bud, I am afraid my background is more android with respect to mobile but this script is ubiquitous I think anyway…
Take this script below and add it to your camera in a new and empty scene.
.
If you have “Unity Remote” then have that ready t o go, before runnign in editor, or deploy it to your mobile device (iphone) and then tell me what happens when place one and then up to all of your fingers down on the screen.
If you read the string msg`s in the code, you can see you should also be able to obtain info about number of taps, each fingers ID and phase alongside positional info of touch vector
You should see a set of debug data when running.
(This is the Unity version which has both been an excellent start point for mobile development, regardless of platform)
I have just run this again myself to be sure it works, and on Android it certainly does work.
Script below, to add to camera in an empty scene…
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TouchScript : MonoBehaviour
{
private List<Touch> mTouch = new List<Touch>();
// Use this for initialization
// Update is called once per frame
void Update()
{
//you could do somthing with the touches by adding them to a list for example
foreach(Touch t in Input.touches)
{
mTouch.Add(Input.GetTouch(0));
}
}
void OnGUI()
{
foreach (Touch t in Input.touches)
{
string message = "";
message += "ID: " + t.fingerId + "
";
message += "Phase: " + t.phase.ToString() + "
";
message += "TapCount: " + t.tapCount + "
";
message += "PositionX: " + t.position.x + "
";
message += "PositionY: " + t.position.y + "
";
int num = t.fingerId;
GUI.Label(new Rect(0 + 130 * num, 0, 120, 100), message);
}
}
}
Hope that helps you resolve the problem bud, take care for now.
Gruffy