Advertisement
GUPPYYYY

Movement

Sep 10th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 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.     // Update is called once per frame
  26.     void Update()
  27.     {
  28.         HandlePlayerMovement();
  29.  
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement