Search Unity

Swipe Menus not working

Discussion in 'Scripting' started by ___fROZEN, Feb 27, 2015.

  1. ___fROZEN

    ___fROZEN

    Joined:
    Jun 13, 2013
    Posts:
    11
    Well I have this problem with the menus in my game. I want to have 2 menus that you can individually swipe to make them enter the screen and make them go back by swiping the other way (eg, Facebook).

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MenuMover : MonoBehaviour
    5. {
    6.     public static MenuMover instance;
    7.  
    8.     public bool swipedLeft;
    9.     public bool swipedRight;
    10.  
    11.     public Vector3 addMenuEnd;
    12.     public Vector3 addMenuStart;
    13.  
    14.     public Vector3 saveLoadMenuEnd;
    15.     public Vector3 saveLoadMenuStart;
    16.  
    17.     public bool one;
    18.  
    19.     public GameObject addMenu;
    20.     public GameObject saveLoadMenu;
    21.  
    22.     void Start ()
    23.     {
    24.         instance = this;
    25.  
    26.         saveLoadMenuStart = saveLoadMenu.transform.position;
    27.         addMenuStart = addMenu.transform.position;
    28.     }
    29.  
    30.     void Update ()
    31.     {
    32.         if(swipedLeft)
    33.         {
    34.             addMenu.transform.position = Vector3.Lerp(addMenu.transform.position , addMenuEnd , Time.deltaTime * 10);
    35.  
    36.             one = true;
    37.         }
    38.  
    39.         if(swipedRight)
    40.         {
    41.             addMenu.transform.position = Vector3.Lerp(addMenu.transform.position , addMenuStart , Time.deltaTime * 10);
    42.  
    43.             one = false;
    44.         }
    45.  
    46.         if(swipedLeft)
    47.         {
    48.             saveLoadMenu.transform.position = Vector3.Lerp(saveLoadMenu.transform.position , saveLoadMenuStart , Time.deltaTime * 10);
    49.         }
    50.  
    51.         if(swipedRight && !one)
    52.         {
    53.             saveLoadMenu.transform.position = Vector3.Lerp(saveLoadMenu.transform.position , saveLoadMenuEnd , Time.deltaTime * 10);
    54.         }
    55.     }
    56.  
    57.     public void SwipeLeft ()
    58.     {
    59.         swipedLeft = true;
    60.         swipedRight = false;
    61.     }
    62.  
    63.     public void SwipeRight ()
    64.     {
    65.         swipedLeft = false;
    66.         swipedRight = true;
    67.     }
    68. }
    69.  
    Sorry for they messy and probably expensive code.

    Please really need help!

    Thank You!
     
  2. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    Are you looking for something like the minute 1:56 of this video?



    If so... i have made that using just camera animation... create two animation, one to go to left, and another one to return (the same one but inverted)... and interact them with animation.CrossFade