- Home /
Two player touch screen
I'm trying to create a game in which two players play on the same device. One player (hereinafter Player1) will control a character while the other player (hereinafter Player2) spawns enemies. Player 1 moves with a simple raycast script to follow the finger. It is detected as Mouse(0). Inside a rectangle that is the bottom half of the screen, a Mouse(1) hit makes the Player1 attack. This all works just fine. The issue comes when trying to spawn the enemies. I cannot work out touchId or get it to identify as any mouse buttons when I click the spawn button. I have tried GUI.button, GUItexture, and detecting touches within a rectangle. If Player(1) is moving, Player2 cannot spawn enemies. I am coding in C#. I can post scripts if needed. Thanks in advance.
It would help if you posted the code you use to manage the input from the users. Also, if you are managing many touches I suggest you use the Input.touch and Input.Touches directly and forget about $$anonymous$$ouse. Check the tutorial on multi touch here.
If it is not spawning enemies when the other player is touching and directing the player, it's because of $$anonymous$$ouse(0). As Andres said, use input.touch.
Answer by rsMici · Nov 07, 2014 at 09:38 AM
Are you using code like this? I just managed to get my working for two player touch input.
if (Input.touchCount == 1) {
Touch touch = Input.GetTouch(0);
else if (Input.touchCount == 2) {
Touch touch = Input.GetTouch(0);
Touch touch2 = Input.GetTouch(1);
Hope i helped you :) took me few days
That one though only works with two fingers. If you put it in a for loop as the documentation says, you can detect as many fingers as your screen can handle.
Thanks for the quick response. I am not home at the moment but will try this and let you know my results as soon as I get home.
I'm running into an issue in that the mul$$anonymous$$ch should work across multiple scripts. I am also not sure what to do with the touches once i have them. Would you do something like if(Input.touches[touch].phase == Touchphase.began) {
or something else? I can't seem to figure it out.