lucax
March 26, 2014, 11:57am
1
I am using simple swipe control for left right as follows :
//Initializing fp and lp as vector2
foreach (Touch touch in Input.touches) {
if(touch.phase == TouchPhase.Began)
{
Debug.Log ("Touch Began");
fp = touch.position;
lp = touch.position;
}
if(touch.phase == TouchPhase.Moved)
{
lp = touch.position;
}
if(touch.phase == TouchPhase.Ended)
{
if((fp.x - lp.x) > 50)
{
//Left Swipe
Debug.Log ("Swiped Left!");
}
//... continuing down
Now the deal is I want a circle swipe, and if I try to use && operator in the above condition to make a condition that include up and left it will perform both up and left swipe rather than a circle.
In short I am looking for a way to implement a Swipe when user makes a circle on screen.
Also I’ve seen a few plugins so far none had circle or similar if you suggest one make sure it has in it.
using UnityEngine;
using System.Collections;
public class SwipeDetector : MonoBehaviour
{
public float minSwipeDistY;
public float minSwipeDistX;
private Vector2 startPos;
void Update()
{
//#if UNITY_ANDROID
if (Input.touchCount > 0)
{
Touch touch = Input.touches[0];
switch (touch.phase)
{
case TouchPhase.Began:
startPos = touch.position;
break;
case TouchPhase.Ended:
float swipeDistVertical = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;
if (swipeDistVertical > minSwipeDistY)
{
float swipeValue = Mathf.Sign(touch.position.y - startPos.y);
if (swipeValue > 0)//up swipe
//Jump ();
else if (swipeValue < 0)//down swipe
//Shrink ();
}
float swipeDistHorizontal = (new Vector3(touch.position.x,0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;
if (swipeDistHorizontal > minSwipeDistX)
{
float swipeValue = Mathf.Sign(touch.position.x - startPos.x);
if (swipeValue > 0)//right swipe
//MoveRight ();
else if (swipeValue < 0)//left swipe
//MoveLeft ();
}
break;
}
}
}
}
Do you mean like a joystick so the player never has to take the finger off the screen?
If so check out the Penelope tutorial by unity tech
Our there are scripts in the standard assets that you can look over