Ejemplo n.º 1
0
    //Funtion to move player game side by side
    void moveLeftRight()
    {
        Vector2 sideTarget = rb.position;


        if (Input.GetKeyDown(KeyCode.LeftArrow) || Swipe.swipe == Swipe.SwipeDirection.left || ScreenSideTouch.side == ScreenSideTouch.SideTouched.leftSide)
        {
            Swipe.ResetSwipe();
            if (sidePosition.x > -2)
            {
                sidePosition.x -= sideDistance;
            }
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow) || Swipe.swipe == Swipe.SwipeDirection.right || ScreenSideTouch.side == ScreenSideTouch.SideTouched.rightSide)
        {
            ScreenSideTouch.ResetTouch();
            Swipe.ResetSwipe();
            if (sidePosition.x < 2)
            {
                sidePosition.x += sideDistance;
            }
        }

        sideTarget.x = Mathf.MoveTowards(sideTarget.x, sidePosition.x, Time.deltaTime * (gameSpeed + 3.5f));
        rb.position  = sideTarget;
    }
 // Update is called once per frame
 void Update()
 {
     if ((Input.GetKeyUp(KeyCode.RightArrow)) ||
         Swipe.swipe == Swipe.SwipeDirection.right)
     {
         Swipe.ResetSwipe();
         right = 0;
     }
     if ((Input.GetKeyUp(KeyCode.LeftArrow)) ||
         Swipe.swipe == Swipe.SwipeDirection.left)
     {
         Swipe.ResetSwipe();
         left = 0;
     }
     if (((Input.GetKeyUp(KeyCode.Space)) ||
          Swipe.swipe == Swipe.SwipeDirection.up) && ground)
     {
         Swipe.ResetSwipe();
         jump = 0;
     }
     ActivateTrainsInRange();
     CheckifDied();
     UpDateSkybox();
 }