Help with Multitouch input on Android - Unity
Hi Guys,
I'm busy trying to port my comp E game to play on Android Touch devices. It's all new to me and I am a bit lost and need help. My game was set up in such a way that the character movement was handled with AWSD and my shooting with the ARROW keys (kinda like a twin stick shooter). All my animations and movement used Input.GetkeyDown and Input.GetKeyUp type logic. I am using the new GUI Canvas Images as my buttons. Each of these buttons has 2 scripts attached to it. My button logic, which is a hacky way of getting getkeydown and getkeyup behavior and then a second script (unique for each button) to say what the button needs to do when the button is up or when the button is down. Basically change the values of static public bools in my character movement script. Here is an example of the code attached to my move up button:
Button Logic:
Up Button Script:
Now this all works fine, and each button does what it is supposed to do. The problem is that is not allowing for multiple touches. Example: I can move up (with up button), and I can shoot up (with shoot up button), but I cannot move up and shoot up at the same time (press both up button and shoot up button). I tried google but couldn't find anything that made sense. A lot of the advice out there is still for GUItextures in stead of Canvas Images. Can anyone assist me please!!!! As I said this is my first attempt at anything Touch and I have no idea what I'm doing.
Thanks
I'm busy trying to port my comp E game to play on Android Touch devices. It's all new to me and I am a bit lost and need help. My game was set up in such a way that the character movement was handled with AWSD and my shooting with the ARROW keys (kinda like a twin stick shooter). All my animations and movement used Input.GetkeyDown and Input.GetKeyUp type logic. I am using the new GUI Canvas Images as my buttons. Each of these buttons has 2 scripts attached to it. My button logic, which is a hacky way of getting getkeydown and getkeyup behavior and then a second script (unique for each button) to say what the button needs to do when the button is up or when the button is down. Basically change the values of static public bools in my character movement script. Here is an example of the code attached to my move up button:
Button Logic:
using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections; public class TouchButtonsLogic : MonoBehaviour, IPointerDownHandler, IPointerUpHandler { private int pointerID; public void OnPointerDown (PointerEventData data) { pointerID = data.pointerId; this.SendMessage("TouchyDown"); } public void OnPointerUp (PointerEventData data) { if (data.pointerId == pointerID) { this.SendMessage("TouchyUp"); } } }
Up Button Script:
using UnityEngine; using System.Collections; public class UpTouchButton : MonoBehaviour { void TouchyDown() { CharacterMovement.SPressed = false; CharacterMovement.Slifted = false; CharacterMovement.WPressed = true; CharacterMovement.Wlifted = false; CharacterMovement.APressed = false; CharacterMovement.Alifted = false; CharacterMovement.DPressed = false; CharacterMovement.Dlifted = false; CharacterMovement.WDPressed = false; CharacterMovement.WDlifted = false; CharacterMovement.WAPressed = false; CharacterMovement.WAlifted = false; CharacterMovement.SDPressed = false; CharacterMovement.SDlifted = false; CharacterMovement.SAPressed = false; CharacterMovement.SAlifted = false; } void TouchyUp() { CharacterMovement.SPressed = false; CharacterMovement.Slifted = false; CharacterMovement.WPressed = false; CharacterMovement.Wlifted = true; CharacterMovement.APressed = false; CharacterMovement.Alifted = false; CharacterMovement.DPressed = false; CharacterMovement.Dlifted = false; CharacterMovement.WDPressed = false; CharacterMovement.WDlifted = false; CharacterMovement.WAPressed = false; CharacterMovement.WAlifted = false; CharacterMovement.SDPressed = false; CharacterMovement.SDlifted = false; CharacterMovement.SAPressed = false; CharacterMovement.SAlifted = false; } }
Now this all works fine, and each button does what it is supposed to do. The problem is that is not allowing for multiple touches. Example: I can move up (with up button), and I can shoot up (with shoot up button), but I cannot move up and shoot up at the same time (press both up button and shoot up button). I tried google but couldn't find anything that made sense. A lot of the advice out there is still for GUItextures in stead of Canvas Images. Can anyone assist me please!!!! As I said this is my first attempt at anything Touch and I have no idea what I'm doing.
Thanks
Comments
Assets --> Import Package --> Cross Platform Input. Look for a prefab called DualTouchControls in the prefabs folder.
EDIT: Also available for Unity 4.6
I do have another question though:
If I "Build and Run" the game gets sent to my device. But how would I go about getting the game onto other devices without connecting them to my PC, or posting an Android build here for instance? If I just build, Unity gives me a single .apk file, what do I do with this? Sorry for the noob questions, but as stated earlier, I am completely new to this.