- Home /
Simultaneous Touch Drag Controls
HI all, I was wondering if anyone can help in my predicament.
I am currently trying to split my screen in half on my device which I have achieved using
if (touch.position.y < Screen.height/2)
if (touch.position.y > Screen.height/2)
The allow 2 people playing the game at the same time to control on paddle on each side of the screen. At the moment I cannot get this to work. One player MUST be holding the screen to allow the other to move.
Can anyone help?
Thanks
You need to provide your code. And explain what you mean by "holding the screen".
As a foreplay, here is what you can do:
foreach(Touch touch in Input.touches)
{
if (touch.position.y < Screen.height/2) { // Player 1 }
if (touch.position.y > Screen.height/2) { // Player 2 }
}
But maybe you already have that.
Thanks for the reply.
By holding I mean dragging the paddles on each end of the screen just like a 2 player PONG match.
I have this code on both game objects (Screen height different on each one) ----
function Update () {
if(Input.touchCount > 0 )
{
var touch = Input.GetTouch(0);
var myTouches = Input.touches;
{
if (touch.position.y > Screen.height/2)
{
// if (Input.touches[0].phase == TouchPhase.$$anonymous$$oved)
{
var x = Input.touches[i].deltaPosition.x *speed* Time.deltaTime;
var y = Input.touches[i].deltaPosition.y *speed* Time.deltaTime;
transform.Translate( new Vector3(x, 0 ) );
Side note: it seems wrong to multiply deltaPosition times deltaTime. Using deltaPosition alone should make the speed of the game independent of the fps but multiplying it by deltaTime will make the players move faster the lower the fps is.