2D android swipe movement,2D Mobile Movement
Hi, I am new to both unity and C#. Now, I am making 2D android game, but have problem with swipe type movement. This is the code:
private void FixedUpdate ()
{
if(Input.touchCount > 0)
{
tap = Input.GetTouch(0);
switch (tap.phase)
{
case TouchPhase.Began:
startPos.x = tap.position.x;
break;
case TouchPhase.Moved:
endPos = new Vector2 (tap.position.x - startPos.x, 0.0f);
rb.AddForce(endPos * speed);
break;
case TouchPhase.Ended:
tap.position = new Vector2(0.0f, 0.0f);
break;
}
}
}
} can you tell me what is wrong? In idea this code should give my player, basic swipe motion?,Hi, I am new to both unity and C# scripting. I am writing an android 2D game, but have problem with movement control. This is my Code: using System.Collections; using System.Collections.Generic;
private void FixedUpdate ()
{
if(Input.touchCount > 0)
{
tap = Input.GetTouch(0);
switch (tap.phase)
{
case TouchPhase.Began:
startPos.x = tap.position.x;
break;
case TouchPhase.Moved:
endPos = new Vector2 (tap.position.x - startPos.x, 0.0f);
rb.AddForce(endPos * speed);
break;
case TouchPhase.Ended:
tap.position = new Vector2(0.0f, 0.0f);
break;
}
}
}
} Can you tell me what is the problem?
Your answer
Follow this Question
Related Questions
Mobile Development with Respect to Screen Resolution 0 Answers
How to make so that the player can jump on a object, but he can't stand on it? (2D) 0 Answers
Re sizing an object within a confined space 0 Answers
Graphics.PresentAndSync (Device.Present) on mobile devices problem 0 Answers
Player Vibration on collision - AddForce Vs transform.Translate 0 Answers