It is necessary to make so that moving the finger to the right / left switches the scene.

    2 answers 2

    You can track svayp this way (taken from here )

    private Vector3 fp; //ΠŸΠ΅Ρ€Π²Π°Ρ позиция касания private Vector3 lp; //ПослСдняя позиция касания private float dragDistance; //Минимальная дистанция для опрСдСлСния свайпа private List<Vector3> touchPositions = new List<Vector3>(); //Π₯Ρ€Π°Π½ΠΈΠΌ всС ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ касания Π² спискС void Start(){ dragDistance = Screen.height*20/100; //dragDistance это 20% высоты экрана } foreach (Touch touch in Input.touches) //ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ Ρ†ΠΈΠΊΠ» для отслСТивания большС ΠΎΠ΄Π½ΠΎΠ³ΠΎ свайпа { //Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ Π·Π°ΠΊΠΎΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Ρ‹, Ссли Π²Ρ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚Π΅ списки /*if (touch.phase == TouchPhase.Began) //провСряСм ΠΏΠ΅Ρ€Π²ΠΎΠ΅ касаниС { fp = touch.position; lp = touch.position; }*/ if (touch.phase == TouchPhase.Moved) //добавляСм касания Π² список, ΠΊΠ°ΠΊ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΎΠ½ΠΈ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ { touchPositions.Add(touch.position); } if (touch.phase == TouchPhase.Ended) //провСряСм, Ссли ΠΏΠ°Π»Π΅Ρ† убираСтся с экрана { //lp = touch.position; //послСдняя позиция касания. Π·Π°ΠΊΠΎΠΌΠ΅Π½Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ Ссли ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚Π΅ списки fp = touchPositions[0]; //ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ ΠΏΠ΅Ρ€Π²ΡƒΡŽ ΠΏΠΎΠ·ΠΈΡ†ΠΈΡŽ касания ΠΈΠ· списка касаний lp = touchPositions[touchPositions.Count-1]; //позиция послСднСго касания //провСряСм Π΄ΠΈΡΡ‚Π°Π½Ρ†ΠΈΡŽ пСрСмСщСния большС Ρ‡Π΅ΠΌ 20% высоты экрана if (Mathf.Abs(lp.x - fp.x) > dragDistance || Mathf.Abs(lp.y - fp.y) > dragDistance) {//это ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅ //провСряСм, ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π΅Π½ΠΈΠ΅ Π±Ρ‹Π»ΠΎ Π²Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΌ ΠΈΠ»ΠΈ Π³ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½Ρ‹ΠΌ if (Mathf.Abs(lp.x - fp.x) > Mathf.Abs(lp.y - fp.y)) { //Если Π³ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½ΠΎΠ΅ Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ большС, Ρ‡Π΅ΠΌ Π²Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΡŒΠ½ΠΎΠ΅ Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ ... if ((lp.x>fp.x)) //Если Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ Π±Ρ‹Π»ΠΎ Π²ΠΏΡ€Π°Π²ΠΎ { //Π‘Π²Π°ΠΉΠΏ Π²ΠΏΡ€Π°Π²ΠΎ Debug.Log("Right Swipe"); } else { //Π‘Π²Π°ΠΉΠΏ Π²Π»Π΅Π²ΠΎ Debug.Log("Left Swipe"); } } else { //Если Π²Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΡŒΠ½ΠΎΠ΅ Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ большС, Ρ‡Π½ΠΌ Π³ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½ΠΎΠ΅ Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ if (lp.y>fp.y) //Если Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ Π²Π²Π΅Ρ€Ρ… { //Π‘Π²Π°ΠΉΠΏ Π²Π²Π΅Ρ€Ρ… Debug.Log("Up Swipe"); } else { //Π‘Π²Π°ΠΉΠΏ Π²Π½ΠΈΠ· Debug.Log("Down Swipe"); } } } } else { //Π­Ρ‚ΠΎ ΠΎΡ‚Π²Π΅Ρ‚Π²Π»Π΅Π½ΠΈΠ΅, ΠΊΠ°ΠΊ расстояниС пСрСмСщСния составляСт ΠΌΠ΅Π½Π΅Π΅ 20% ΠΎΡ‚ высоты экрана } } } 

    And then load the stage

      if ((lp.x>fp.x)) //Если Π΄Π²ΠΈΠΆΠ΅Π½ΠΈΠ΅ Π² ΠΏΡ€Π°Π²ΠΎ { //Π‘Π²Π°ΠΉΠΏ Π²Π²Π΅Ρ€Ρ… SceneManager.LoadScene(1); } 

      Track svayp) for example, when a button is pressed / touched, remember the position when the button is released - read the distance between these points.

      If it corresponds to the one in which you want to change the scene, tell SceneManager to load the new scene.

      • I have some ideas, could you tell me in what ways it can be traced? - DmitryDAN
      • one
        @DmitryDAN, well, from the most banal. Hang some MonoBehaviour, which in Update checks and whether LMB was pressed in this frame and released. In the first case - we remember the current position of the cursor, in the second we calculate the distance between the current and memorized when pressed, we compare it with the distance you set for the shift. If it is equal or more - load a new scene - M. Green