swipe normalement fini

This commit is contained in:
esteb
2023-01-11 17:17:41 +01:00
parent eac60bc9dd
commit b27fecb9d1
10 changed files with 698 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SwipeScript : MonoBehaviour
{
public Image imageText;
public List<Sprite> 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];
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f407ae763bb9f404da14bcd89415c092
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: