i currently am using a script that can be used for pc and mobile use, which is like a runner game where you tap on different points on the screen to change “Lanes” to dodge out the way and such. However it was suggested to me that it would make the movement a lot easier and better if i made it a swipe to change lanes rather than tap. Im currently using invisible ui buttons for the taps. Here is the script that controls the lanes and normal tap/key movements. If this is not possible with ui, i’m open to suggestions on what i could do to get the effect im seeking.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
public KeyCode[] LaneInputs = new KeyCode[]
{
KeyCode.S,
KeyCode.D,
KeyCode.A
};
public float snapSpeed = 10f;
public Transform[] Lanes;
public GameObject Empty;
public GameObject Bounce;
private Transform targetLane;
private Vector3 EmptyOffset = new Vector3(0, 0.2f, 0);
private Vector3 SquashScale = new Vector3(1, 0.5f, 1);
private Vector3 FullScale = Vector3.one;
void Update()
{
int minSize = Mathf.Min(LaneInputs.Length, Lanes.Length);
for (int i = 0; i < minSize; i++)
{
if (Input.GetKeyDown(LaneInputs[i]))
{
targetLane = Lanes[i];
}
}
if (targetLane != null)
{
transform.position = Vector3.MoveTowards(transform.position, targetLane.position, snapSpeed * Time.deltaTime);
}
}
public void First()
{
int minSize = Mathf.Min(LaneInputs.Length, Lanes.Length);
for (int i = 0; i < minSize; i++)
{
targetLane = Lanes[2];
}
}
public void Second()
{
int minSize = Mathf.Min(LaneInputs.Length, Lanes.Length);
for (int i = 0; i < minSize; i++)
{
targetLane = Lanes[0];
}
}
public void Third()
{
int minSize = Mathf.Min(LaneInputs.Length, Lanes.Length);
for (int i = 0; i < minSize; i++)
{
targetLane = Lanes[1];
}
}
}