Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (Input.touchCount > 0)
- {
- Touch touch = Input.GetTouch(0);
- if(touch.phase == TouchPhase.Began)
- {
- startTime = Time.time;
- startPos = touch.position;
- }
- else if (touch.phase == TouchPhase.Ended)
- {
- endTime = Time.time;
- endPos = touch.position;
- swipeDistance = (endPos - startPos).magnitude;
- swipeTime = endTime - startTime;
- if (swipeTime < maxTime && swipeDistance > minSwipeDist)
- {
- Swipe();
- }
- }
- }
- }
- public void Swipe()
- {
- Vector2 distance = endPos - startPos;
- if(Mathf.Abs(distance.x) > Mathf.Abs(distance.y))
- {
- Debug.Log("Horizontal Swipe");
- if(distance.x > 0)
- {
- Debug.Log("Right Swipe");
- CC.center = new Vector3(0, 1.28f, 0);
- CC.height = 2.52f;
- transform.Translate(Vector3.right * rightSpeed * Time.deltaTime);
- }
- if(distance.x < 0)
- {
- Debug.Log("Left Swipe");
- CC.center = new Vector3(0, 1.28f, 0);
- CC.height = 2.52f;
- transform.Translate(Vector3.left * leftSpeed * Time.deltaTime);
- }
- }
- PLAYER NOT MOVING SMOOTHLY INSTEAD HE "JUMPS TO THE RIGHT AND LEFT" CUTS FRAMES... OR SOMETHING... LIKE NO FLOAT.. "FRAME JUMPING"
- Anyone ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement