Advertisement
johnnygoodguy2000

PlayerController

Mar 22nd, 2024
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem;
  5.  
  6.  
  7. public class PlayerControllerTutorialUpdates : MonoBehaviour
  8. {
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12.  
  13.  
  14. }
  15.  
  16.  
  17. // Update is called once per frame
  18. void Update()
  19. {
  20.     float horizontal = 0.0f;
  21.     if (Keyboard.current.leftArrowKey.isPressed)
  22.     {
  23.         horizontal = -1.0f;
  24.         }
  25.     else if (Keyboard.current.rightArrowKey.isPressed)
  26.     {
  27.         horizontal = 1.0f;
  28.     }
  29.     Debug.Log(horizontal);
  30.  
  31.  
  32.     float vertical = 0.0f;
  33.     if (Keyboard.current.upArrowKey.isPressed)
  34.     {
  35.         vertical = 1.0f;
  36.     }
  37.     else if (Keyboard.current.downArrowKey.isPressed)
  38.     {
  39.         vertical = -1.0f;
  40.     }
  41.     Debug.Log(vertical);
  42.  
  43.  
  44.     Vector2 position = transform.position;
  45.     position.x = position.x + 0.1f * horizontal;
  46.     position.x = position.x + 0.1f * vertical;
  47.     transform.position = position;
  48. }
  49.  
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement