Advertisement
EdGr87

Untitled

Jan 13th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. ```
  2. void Update() {
  3.  
  4.         if (_isPlayerOne) {
  5.             CalculateMovement(1);
  6.             PlayerBounds();
  7.  
  8.             if (Input.GetKeyDown(KeyCode.Space) && Time.time > _canFire && _isPlayerOne == true) {
  9.                 _canFire = Time.time + _fireRate;
  10.                 ShootLaser(_isTripleShotEnabled);
  11.  
  12.  
  13.             }
  14.         }
  15.  
  16.         if (_isPlayerTwo) {
  17.             CalculateMovement(2);
  18.             PlayerBounds();
  19.  
  20.             if (Input.GetKeyDown(KeyCode.RightShift) && Time.time > _canFire && _isPlayerTwo == true) {
  21.                 _canFire = Time.time + _fireRate;
  22.                 ShootLaser(_isTripleShotEnabled);
  23.             }
  24.         }
  25.     }
  26.  
  27.     private void CalculateMovement(int PlayerNumber) {
  28.  
  29.         switch (PlayerNumber) {
  30.  
  31.             case 1:
  32.  
  33.                 float HorizontalInput = Input.GetAxis("Horizontal");
  34.                 float VerticalInput = Input.GetAxis("Vertical");
  35.  
  36.                 Vector3 direction = new(HorizontalInput, VerticalInput, 0);
  37.  
  38.                 _animator.SetFloat("PlayerTurn", HorizontalInput);
  39.                 _animator.SetInteger("OriginalPos", (int)HorizontalInput);
  40.  
  41.                 transform.Translate(direction * _playerSpeed * Time.deltaTime);
  42.  
  43.                 break;
  44.  
  45.             case 2:
  46.  
  47.                 if (Input.GetKeyDown(KeyCode.Keypad8)) {
  48.                     transform.Translate(Vector3.up * _playerSpeed * Time.deltaTime);
  49.                 }
  50.  
  51.                 if (Input.GetKeyDown(KeyCode.Keypad2)) {
  52.                     transform.Translate(Vector3.down * _playerSpeed * Time.deltaTime);
  53.                 }
  54.  
  55.                 if (Input.GetKeyDown(KeyCode.Keypad4)) {
  56.                     transform.Translate(Vector3.left * _playerSpeed * Time.deltaTime);
  57.                 }
  58.  
  59.                 if (Input.GetKeyDown(KeyCode.Keypad6)) {
  60.                     transform.Translate(Vector3.right * _playerSpeed * Time.deltaTime);
  61.                 }
  62.  
  63.                 break;
  64.         }
  65.     }
  66. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement