Ejemplo n.º 1
0
    // Start is called before the first frame update
    private void Start()
    {
        p_continuePlaneScale    = m_continuePlane.transform.localScale;
        p_levelselectPlaneScale = m_levelselectPlane.transform.localScale;

        m_contButton.onClick.AddListener(OnClickContinue);

        //move the camera outside so it can swipe in
        p_cameraInsidePosition = m_camera.transform.position;
        m_camera.transform.Translate(-20, 0, 0);
        p_cameraOutsidePosition = m_camera.transform.position;
        p_cameraSmoothTime      = 0.3f;

        p_lastLevelChange = 1;
        p_triggerDistance = Screen.width * 0.1f; //if 10% of the screen has been touchmoved

        LoadPreview(MemoryCard.GetSelectedLevelIndex());
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    private void Update()
    {
        //return key pressed?
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            p_nextScene   = true;
            p_returnScene = true;
        }

        //check touch controls
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            //save the touch and swipe positions
            switch (touch.phase)
            {
            case TouchPhase.Began:
                p_startPos = touch.position;
                break;

            case TouchPhase.Moved:
                p_direction = touch.position - p_startPos;
                break;

            case TouchPhase.Ended:
                p_direction.x = 0;
                p_direction.y = 0;
                break;
            }
        }

        //if the player swiped for a certain distance, start to load new map
        if (Mathf.Abs(p_direction.x) > p_triggerDistance)
        {
            //dont change map to frequently
            if (Time.time - p_lastLevelChange > 0.3f)
            {
                p_lastLevelChange = Time.time;

                //change to next or previous map and set animatin accordingly
                if (p_direction.x < 0)
                {
                    MemoryCard.AddToSelectedLevel(+1);
                    p_mapGoToThisPosition = p_mapLeftPosition;
                }
                else
                {
                    MemoryCard.AddToSelectedLevel(-1);
                    p_mapGoToThisPosition = p_mapRightPosition;
                }
            }
        }

        //change scene once the camera finished animation
        if (p_nextScene && m_camera.transform.position.x < -19)
        {
            if (p_returnScene)
            {
                MemoryCard.LoadMenu();
            }
            else
            {
                MemoryCard.LoadSelectedLevel();
            }
        }

        //animate
        AnimateScreenTransitions();
        AnimateMapTransition();
        AnimateScreen();

        //if the map has finished animation, load a new map
        if (p_currentMapPreview.transform.position.x < -19 || p_currentMapPreview.transform.position.x > 19)
        {
            LoadPreview(MemoryCard.GetSelectedLevelIndex()); //load currently selected level
        }
    }