using UnityEngine; using UnityEngine.EventSystems; using DG.Tweening; using System.Collections.Generic; public class SilderUI : MonoBehaviour, IDragHandler, IEndDragHandler { public SceneBtn sceneBtn; private float swipeThreshold = 10f; // 滑动切换的阈值 private void Start() { } public void OnDrag(PointerEventData eventData) { } public void OnEndDrag(PointerEventData eventData) { float dragDistance = eventData.pressPosition.x - eventData.position.x; Debug.Log(dragDistance); bool toNext = dragDistance > 0; // 判断是向左还是向右滑动 if (toNext) { JumpScene.jumpbool += 1; } else { JumpScene.jumpbool -= 1; } if (JumpScene.jumpbool < 0) { JumpScene.jumpbool = 4; } if (JumpScene.jumpbool >4) { JumpScene.jumpbool = 0; } if (Mathf.Abs(dragDistance) >= swipeThreshold) { sceneBtn.BeginLoad(JumpScene.jumpbool); } } }