This commit is contained in:
esteb
2023-01-18 10:49:44 +01:00
parent 9b77de958c
commit 99b52ecf4c
48 changed files with 4811 additions and 158 deletions

View File

@@ -0,0 +1,95 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class SwipeManagementScript : MonoBehaviour
{
public TMP_Text textSteps;
public List<Text> lengths;
public int numberImage;
public int lengthTexts;
public GameObject arrowLeft;
public GameObject arrowRight;
public GameObject imgDown;
public GameObject imgUp;
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 < startTouchPosition.y){
SwipeDown();
} else {
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(){
imgDown.SetActive(true);
imgUp.SetActive(false);
}
private void SwipeUp(){
imgDown.SetActive(false);
imgUp.SetActive(true);
}
}

View File

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

View File

@@ -2,17 +2,21 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class SwipeScript : MonoBehaviour
{
public Text textSteps;
public TMP_Text textSteps;
public List<Text> lengths;
public int numberImage;
public int lengthTexts;
public Button arrowLeft;
public Button arrowRight;
public Button quit;
public GameObject canvas1;
public GameObject canvas2;
private Vector2 startTouchPosition;
private Vector2 endTouchPosition;
@@ -22,9 +26,11 @@ public class SwipeScript : MonoBehaviour
{
Button btnLeft = arrowLeft.GetComponent<Button>();
Button btnRight = arrowRight.GetComponent<Button>();
Button btnQuit = quit.GetComponent<Button>();
arrowLeft.gameObject.SetActive(false);
btnLeft.onClick.AddListener(PreviousText);
btnRight.onClick.AddListener(NextText);
btnQuit.onClick.AddListener(Quit);
textSteps.text = lengths[0].text;
}
@@ -36,11 +42,15 @@ public class SwipeScript : MonoBehaviour
}
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){
endTouchPosition = Input.GetTouch(0).position;
if(endTouchPosition.x < startTouchPosition.x){
/* if(endTouchPosition.x < startTouchPosition.x){
NextText();
}
if(endTouchPosition.x > startTouchPosition.x){
}else{
PreviousText();
}*/
if(endTouchPosition.y < startTouchPosition.y){
SwipeDown();
} else {
SwipeUp();
}
}
}
@@ -75,4 +85,21 @@ public class SwipeScript : MonoBehaviour
textSteps.text = lengths[numberImage].text;
}
}
private void Quit(){
canvas1.SetActive(false);
canvas2.SetActive(false);
}
public void Enter(){
canvas1.SetActive(true);
canvas2.SetActive(true);
Debug.Log("Hello: ");
}
private void SwipeDown(){
PreviousText();
}
private void SwipeUp(){
NextText();
}
}