GUPPYYYY

Movement

Sep 10th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour
  6. {
  7.  
  8.  
  9.     public float moveSpeed = 10f;
  10.  
  11.     private float movementX;
  12.  
  13.     private float movementY;
  14.  
  15.     void HandlePlayerMovement()
  16.     {
  17.         movementX = Input.GetAxisRaw("Horizontal");
  18.         movementY = Input.GetAxisRaw("Vertical");
  19.  
  20.         transform.position += new Vector3(movementX, 0f, 0f) * moveSpeed * Time.deltaTime;
  21.         transform.position += new Vector3(0f, movementY, 0f) * moveSpeed * Time.deltaTime;
  22.  
  23.     }
  24.  
  25.     void Update()
  26.     {
  27.         HandlePlayerMovement();
  28.  
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment