using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SwipeScript : MonoBehaviour { public Image imageText; public List lengths; public int numberImage; public int lengthTexts; public GameObject arrowLeft; public GameObject arrowRight; private Vector2 startTouchPosition; private Vector2 endTouchPosition; // Start is called before the first frame update void Start() { } // 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(); } if(endTouchPosition.x > startTouchPosition.x){ PreviousText(); } } } private void NextText(){ numberImage ++; if(numberImage == lengthTexts){ arrowRight.SetActive(false); }else{ arrowRight.SetActive(true); } imageText.sprite = lengths[numberImage]; } private void PreviousText(){ numberImage --; if(numberImage == 0){ arrowLeft.SetActive(false); }else{ arrowLeft.SetActive(true); } imageText.sprite = lengths[numberImage]; } }