Advertisement
kadyr

Untitled

Nov 5th, 2021
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1.     private int currentPos = 0;
  2.     private int maxPoses;
  3.     private int minPoses;
  4.  
  5. void Update(){
  6.         if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
  7.         {
  8.             Move(1);
  9.         }
  10.         else(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
  11.         {
  12.             Move(-1);
  13.         }
  14. }
  15.  
  16.     private void Move(int dir)
  17.     {
  18.         if (dir > 0)
  19.         {
  20.             if (currentPos < maxPoses)
  21.             {
  22.                 transform.position += Vector3.right;
  23.                 currentPos += 1;
  24.             }
  25.         }
  26.         else
  27.         {
  28.             if (currentPos > minPoses)
  29.             {
  30.                 transform.position += Vector3.left;
  31.                 currentPos -= 1;
  32.             }
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement