public void Swiping(){
if(Input.touchCount == 1)
{
touchDuration += Time.deltaTime;
touch = Input.GetTouch(0);
foreach(Touch t in Input.touches)
{
if (t.phase == TouchPhase.Began)
{
initialTouch = t;
}
if (t.phase == TouchPhase.Moved && !hasSwiped)
{
float deltaX = initialTouch.position.x - t.position.x;
float deltaY = initialTouch.position.y - t.position.y;
distance = Mathf.Sqrt((deltaX * deltaX) + (deltaY * deltaY));
bool swipedSideways = Mathf.Abs(deltaX) > Mathf.Abs(deltaY);
bool swipedSidewayss = Mathf.Abs(deltaY) > Mathf.Abs(deltaX);
if (distance >100f)
{
if(swipedSideways && deltaX > 0)//swipe left
{
Debug.Log("LEFT");
animators.SetTrigger ("LEFT");
}
else if(swipedSideways && deltaY < 0)//swipe right
{
Debug.Log("RIGHT");
animators.SetTrigger ("RIGHT");
}
else if(swipedSidewayss && deltaX > 0)//swipe down
{
Debug.Log("DOWN");
animators.SetTrigger ("DOWN");
}
else if(swipedSidewayss && deltaX < 0)//swipe up
{
Debug.Log("UP");
animators.SetTrigger ("UP");
}
hasSwiped = true;
}
}
else if(t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Moved && t.deltaPosition.magnitude < 100f)
{
animators.SetBool("Block",true);
}
if(t.phase == TouchPhase.Ended)
{
if(touchDuration < 0.5f){
StartCoroutine("singleOrDouble");
}
initialTouch =new Touch();
hasSwiped = false;
}
I want to make a game is swipe to 4 directions
and player able to hold to block incoming damage
but when I hold I get the swipe as well because i put swipe as touchphase.moved.
is there any suggestion for it?
:nerd: :nerd: :nerd: