swipe normalement fini
This commit is contained in:
62
Assets/Scripts/SwipeScript.cs
Normal file
62
Assets/Scripts/SwipeScript.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/SwipeScript.cs.meta
Normal file
11
Assets/Scripts/SwipeScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f407ae763bb9f404da14bcd89415c092
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user