Hey guys,
We have been struggling with our code using input touch functions for iOS. We have left and right button controls which should respond according to graph shown below. However the code (attached) has a bug that we cannot figure out. Solution would be much appreciated.
var leftButton : GUITexture;
var rightButton : GUITexture;
private var lastFingerId = -1;
var goLeft : boolean;
ver goRight : boolean;
function Reset () {
//release the finger control and set everything to default
lastFingerId = -1;
goLeft = false;
goRight = false;
}
function Update () {
var count = Input.touchCount;
if ( count == 0 ){
Reset();
}else for (var i: int = 0; i < count; i++){
var touch : Touch = Input.GetTouch(i);
if(leftButton.HitTest(touch.position) (lastFingerId == -1 || lastFingerId != touch.fingerId)){
goLeft = true;
goRight = false;
lastFingerId = touch.fingerId;
}else if (rightButton.HitTest(touch.position) (lastFingerId == -1 || lastFingerId != touch.fingerId)){
goRight = true;
goLeft = false;
lastFingerId = touch.fingerId;
}
if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){
Reset();
}
}
if (goLeft == true){
transform.Translate(-Time.deltaTime * 8, 0, 0, Camera.main.transform);
}
if (goRight == true){
transform.Translate(Time.deltaTime * 8, 0, 0, Camera.main.transform);
}
}
}
THANKS
