So I’ve started developing for iOS and I’ve run into a few troubles.
I’ve got four boolean variables (player1for, player1back, player2for, player2back) , all four of which can be toggled on and off independently.
They turn on when someone touches their region (ie. x>0 and y>0, or x<0 and y>0, or x<0 and y<0, or x>0 and y<0).
This means that if I have all regions pressed at the same time, all four booleans will be on.
Say I touch only three regions, those regions (with their respective booleans) will be on, whilst the other region will be off.
Get the idea?
So, here’s the code:
nTouches = Input.touchCount;
if (nTouches > 0) {
if (isHandheld) {
for(int i = 0; i < nTouches; i++)
{
Touch touch = Input.GetTouch (i);
touchPos = new Vector3 (touch.position.x - Screen.width/2,0, touch.position.y - Screen.height/2);
if (touchPos.x > 0 && touchPos.z > 0) {
moveLord.player2for = true;
} else {
moveLord.player2for = false;
}
if (touchPos.x > 0 && touchPos.z < 0) {
moveLord.player2back = true;
} else {
moveLord.player2back = false;
}
if (touchPos.x < 0 && touchPos.z > 0) {
moveLord.player1back = true;
} else {
moveLord.player1back = false;
}
if (touchPos.x < 0 && touchPos.z < 0) {
moveLord.player1for = true;
} else {
moveLord.player1for = false;
}
DEBUGGER2.text = "[" + touchPos.x + "," + touchPos.y + "]";
}
}
}
So what’s the problem?
Well, I can never have more than one region on (i.e. if player1back is true, player1for, player2back, and player2for is false) at the same time.
It only recognises the most ‘recent’ press.
I’m sure this is just some silly logic error, but right now I’m not exactly seeing it.
I greatly value your opinion, so thanks!