Hello everyone!
I still have not been able to implement the desired behavior: when I swipe once, a sphere have to be rendered on the screen. To the next swipe, the sphere should be replaced with another object (a cube, let's say) and so on until the end of the 'object list'. After a number of seven objects, the whole process should be resumed. I have a piece of code with three objects, but I'm not yet able to detect only one swipe and to change the displayed object accordingly. I am grateful for any idea or help.
public class Swipe : MonoBehaviour {
Controller controller;
public GameObject wall = null;
public GameObject sphere = null;
public GameObject capsule = null;
public Vector3 startPos;
public Vector3 endPos;
List<GameObject> list;
public float distance = 5f;
int count = 0;
//Time to take from start to end
private float lerpTime = 0.02f;
//This will update the lerp time
private float currentLerpTime = 0;
private float _lastGestureTime = 0;
private bool keyHit = false;
// Use this for initialization
void Start () {
controller = new Controller();
controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
controller.Config.SetFloat("Gesture.Swipe.MinLength", 200.0f);
controller.Config.SetFloat("Gesture.Swipe.MinVelocity", 750f);
controller.Config.Save();
startPos = wall.transform.position;
endPos = wall.transform.position + Vector3.up * distance;
list = new List<GameObject>();
}
// Update is called once per frame
void Update()
{
Frame frame = controller.Frame();
GestureList gestures = frame.Gestures();
Hand hand = frame.Hands.Frontmost;
GameObject c = GameObject.Find("Cube");
list.Add(c);
GameObject ca = GameObject.Find("Capsule");
list.Add(ca);
GameObject s = GameObject.Find("Sphere");
list.Add(s);
foreach (GameObject li in list)
{
Debug.Log(li.name);
}
if (hand.IsRight)
{
for (int i = 0; i < gestures.Count; i++)
{
Gesture gesture = gestures[i];
if (gesture.Type == Gesture.GestureType.TYPESWIPE)
{
SwipeGesture Swipe = new SwipeGesture(gesture);
Vector swipeDirection = Swipe.Direction;
if (Time.time - _lastGestureTime > 0.75f && swipeDirection.x < 0)
{
Debug.Log("Left");
currentLerpTime += Time.deltaTime;
if (currentLerpTime >= lerpTime)
{
currentLerpTime = lerpTime;
}
float Perc = currentLerpTime / lerpTime;
list[0].SetActive(false);
list[1].SetActive(false);
list[2].SetActive(true);
_lastGestureTime = Time.time;
}
if (Time.time - _lastGestureTime > 0.75f && swipeDirection.x > 0)
{
Debug.Log("Right");
currentLerpTime += Time.deltaTime;
if (currentLerpTime >= lerpTime)
{
currentLerpTime = lerpTime;
}
float Perc = currentLerpTime / lerpTime;
list[0].SetActive(true);
list[1].SetActive(false);
list[2].SetActive(false);
_lastGestureTime = Time.time;
}
count++;
}
}
}
}
}