generated from VR-Sexe/Unity3DTemplate
106 lines
2.9 KiB
C#
106 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class SwipeScript : MonoBehaviour
|
|
{
|
|
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;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
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;
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|