Hi everyone, I am finishing a pong game in unity, I've found a little problem with the Input of the Control in the screen, (it's for a game in mobile phones). I've used the tutorials of unity lesson for use a array by control the differerent touches of different fingers. I want to do a multiplayer mode when the people can play in the same device in the same screen, I can't do it because the scrips detect like the same object (i have two scrips one for each one). Anyone know how can i do this? Thank you
Answer by Jerm-Red
Mar 10 at 12:06 AM
You'll need to separate the controls of your script. The best method is to probably to separate their areas of control, such that if you tap in the top half of the screen P1 moves to that location, and if you tap the bottom half of the screen P2 then moves.
In code you'll basically detect the touch, and then determine the Y position, and if it's positive it's the top and then if negative it's in the bottom half (this is assuming that Y pos is 0 in the middle of the screen).
The alternative is to use input.touchCount == 1 to mean move P1 and input.touchCount == 2 to mean P2, but that probably won't feel as good, and could easily let players troll each other.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
159 People are following this question.
Android| Camera scrolling
How do I transfer the control to the PC on your android? how to change the script the character animation that would work? what should be done?
Fire Android Soft-key twice - How can I dismiss a video on Android mobile correctly?
How to receive input on specific objects -Android
How can I block Physical Raycasts from going through UI Elements?