Two touches not working as expected
So I've got a little space game where if you touch on the left side of the screen, your ship moves, and if you touch on the right side of the screen, you fire a laser. I'm not sure what's wrong with the code below:
// touches add thrust and fire laser
int tapCount = Input.touchCount;
for(int i = 0; i < tapCount; i++)
{
//Do something with the touches
Touch touch = Input.GetTouch(i);
if (touch.position.x > Screen.width / 2 ) {
FireLaser();
}
if (touch.position.x < Screen.width / 2 ) {
thrusting = true;
}
}
if (tapCount == 0) {
thrusting = false;
}
It doesn't act as expected. A single touch on either side of the screen works as expected (thrusts or fires a laser). But, if while thrusting, you touch on the right side of the screen (so two touches), it will fire a single laser but then won't register further touches on that side of the screen. If you try to fire a second laser while thrusting (again two touches), it doesn't work. You have to release the thrust-touch before you can do another laser-touch.
Basically, while you're holding down on the left side of the screen to move, it only lets you fire laser / only registers one touch on the other side of the screen.
Additionally, if the "FireLaser()" if statement is below the "thrusting" if statement, it doesn't fire a laser at all.
What am I missing here?
That's odd, cause that's kind of what i'm doing with one of my games and it works perfectly. Have you thought about using a store asset like Lean Touch? I haven't used it myself, but I've added it to my arsenal for upco$$anonymous$$g projects and its pretty cool, and free.