unityscript – Moving player with touch Unity3d
So I’m creating this mobile game in unity3D when were u tap the screen the player moves from position like in the game “RUSH”. Now my problem is is that my player quickly moves from position and back when I touch and also keeps swapping positions when I hold the screen. Can someone help me?
private Vector3 targetPos;
public float Xincrement;
public float speed;
void Update()
{
foreach (Touch touch in Input.touches)
{
transform.position = Vector3.MoveTowards(targetPos, transform.position, speed * Time.deltaTime);
if (touch.tapCount == 1)
{
if (transform.position.x <= 1 && transform.position.x >= 0)
{
targetPos = new Vector3(-1, 0, 0);
}
else if (transform.position.x <= 0 && transform.position.x >= -1)
{
targetPos = new Vector3(1, 0, 0);
}
}
}
}
Read more here: Source link