I’m fairly new to Unity as well as C#, and I have game mostly developed, but I can’t figure out one thing. My game is for mobile devices (IE Galaxy S5, iPhone 5s) and I have three buttons on screen that control the movement of my character. One that makes it jump, one that when held, makes it move right, and another that when held, makes it move left. That all works fine, but there is one issue.
If the player is currently holding down either the ‘move left’ or ‘move right’ buttons, then they cannot tap on the jump button in order to jump. If they stop holding the movement buttons and THEN tap the jump button, it works fine.
I have read a few threads on Multitouch, but they all assume/associate with using a single script. Each of my buttons uses a different script in order to keep things simplified and spread out.
The question I have here is: how could I incorporate Multitouch through about 3 different scripts, and allow players to hold down one finger AND press another, but only on the buttons? For reference, here is an image of my game:
As you see, there are the three buttons. The user can move left and right while holding down their associated buttons with ease, but when holding them down, they cannot press the jump button in order to hop up. Remember, the controls are spread out across 3 separate scripts.
Yup, you capture multiple touches with a for loop. here is one for your moving and jumping thing. notice it jumps on begin only and moves on stationary. THats so he’ll only jump once each time you press but continue to move as long as its pressed…
if (Input.touchCount >0)
for (int i = 0; i < Input.touchCount; ++i)
{
RaycastHit2D hit = Physics2D.Raycast(GUICam.ScreenToWorldPoint(Input.touches*.position), Vector2.zero);*
_ if (Input.touches*.phase == TouchPhase.Began)_
_ {*_