I’ve recently come across a problem regarding implemanting multitouch. I’ve looked at unity’s own multitouch help but even when i’m copying the code and try it, it doesn’t work.
This thread shows how to do it:
//The good way;
var tapCount = Input.touchCount;
for ( var i = 0 ; i < tapCount ; i++ ) {
var touch = Input.GetTouch(i);
if( gasButton.HitTest (Input.GetTouch(i).position))
{
throttleForward = 1;
}else
{
throttleForward = 0;
}
if( rightButton.HitTest (Input.GetTouch(i).position))
{
stearC = 1;
}else
{
stearC = 0;
}
}
Now I copied the code and I am not able to press the gasbutton and rightbutton at the same time. I can only press one button at the same time. Isn’t the for loop changing the i value between 1 - 2 and jumping between the touch positions and run the if statements? I’ve must have gotten it all wrong.
I think you’re right that the problem is that both values are changing for both touches. Right now what would occur if you tried to press both buttons is
touch 1 presses gassButton but not rightButton so it sets throttleForward to 1 and stearC to 0
touch 2 presses gassButton but not rightButton so it sets throttleForward to 0 and stearC to 1
so while both touch 1 and touch 2 are being processed it is done in such a way that touch 2 is overriding all effects of touch 1. Instead it would make sense to have the buttons in their default state of 0 and set to 1 only if a touch presses them. For instance
throttleForward = 0;
stearC = 0;
var tapCount = Input.touchCount;
for ( var i = 0 ; i < tapCount ; i++ ) {
var touch = Input.GetTouch(i);
if( gasButton.HitTest (Input.GetTouch(i).position))
{
throttleForward = 1;
}
if( rightButton.HitTest (Input.GetTouch(i).position))
{
stearC = 1;
}
}
Now what should happen is
throttleForward and stearC are both set to 0
touch 1 presses gassButton but not rightButton so it sets throttleForward to 1
touch 2 presses rightButton but not gassButton so it sets stearC to 1