Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Two touches not working as expected

$
0
0
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?

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>