LEFT RIGHT controls iOS

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

… and the bug is?

is it not working at all, do it do something wrong under certain circumstances etc.

The problem is that it works until u have both fingers on the screen, but when u take one off it does not respond the correct way. If you look at the graph than IDLE,LEFT,RIGHT,RIGHT and than it will not work LEFT unless u go IDLE and than LEFT. Basically if u touching with both fingers and release one and touch again it wont respond until release the second one.

You could just check if the finger touch count is equal to 1, this way if a second finger touched the screen it wouldn’t register or if you want the second finger to override the first fingers touch, you would have to keep track of the current finger index, then switch it when more than 1 finger is pressed on the screen.

Hi DexRobinson, could u please clarify ur answer, maybe provide an example of code that u have on mind? Thanks