using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class SwipeManagementScript : MonoBehaviour { public TMP_Text textSteps; public List lengths; public int numberImage; public int lengthTexts; public GameObject arrowLeft; public GameObject arrowRight; public Animator m_Animator; public TMP_Text textNumber; private Vector2 startTouchPosition; private Vector2 endTouchPosition; // Start is called before the first frame update void Start() { textSteps.text = lengths[0].text; textNumber.text = "Step 1/" + lengthTexts; arrowLeft.gameObject.SetActive(false); } // Update is called once per frame void Update() { if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ startTouchPosition = Input.GetTouch(0).position; } if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){ endTouchPosition = Input.GetTouch(0).position; if(endTouchPosition.x < startTouchPosition.x){ NextText(); }else{ PreviousText(); } if(endTouchPosition.y + 100 < startTouchPosition.y){ SwipeDown(); } if(endTouchPosition.y - 100 > startTouchPosition.y){ SwipeUp(); } } } private void NextText(){ if(numberImage < lengthTexts) { numberImage ++; if(numberImage == lengthTexts){ arrowRight.gameObject.SetActive(false); }else{ arrowRight.gameObject.SetActive(true); } if(numberImage != 0){ arrowLeft.gameObject.SetActive(true); } textSteps.text = lengths[numberImage].text; textNumber.text = "Step" + (numberImage+1) + "/" + lengthTexts; } } private void PreviousText(){ if(numberImage > 0) { numberImage --; if(numberImage == 0){ arrowLeft.gameObject.SetActive(false); }else{ arrowLeft.gameObject.SetActive(true); } if(numberImage != lengthTexts){ arrowRight.gameObject.SetActive(true); } textSteps.text = lengths[numberImage].text; textNumber.text = "Step" + (numberImage+1) + "/" + lengthTexts; } } private void SwipeDown(){ m_Animator.ResetTrigger("SwipeUp"); m_Animator.SetTrigger("SwipeDown"); } private void SwipeUp(){ m_Animator.ResetTrigger("SwipeDown"); m_Animator.SetTrigger("SwipeUp"); } }