Advertisement
GigaOrts

PlayerMove

Apr 27th, 2025
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. public class PlayerMove : MonoBehaviour
  6. {
  7.     public Rigidbody2D rgb;
  8.     public SpriteRenderer spriteRenderer;
  9.     private float hor;
  10.     private float ver;
  11.     public float speed = 2f;
  12.  
  13.     void Update()
  14.     {
  15.         hor = Input.GetAxisRaw("Horizontal");
  16.         ver = Input.GetAxisRaw("Vertical");
  17.         rgb.velocity = new Vector2(hor * speed, ver * speed);
  18.  
  19.         if (hor == -1)
  20.         {
  21.             spriteRenderer.flipX  = true;
  22.         }
  23.         else if (hor == 1)
  24.         {
  25.             spriteRenderer.flipX  = false;
  26.         }
  27.  
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement