The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
EASY Unity 2D Top down...
By Guest on 11th November 2022 04:19:07 PM | Syntax: CSHARP | Views: 4



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerCtrl : MonoBehaviour
  6. {
  7.  
  8.  
  9.     public float movSpeed;
  10.     float speedX, speedY;
  11.     Rigidbody2D rb;
  12.  
  13.  
  14.  
  15.     void Start()
  16.     {
  17.         rb = GetComponent<Rigidbody2D>();
  18.  
  19.     }
  20.  
  21.     void Update()
  22.     {
  23.  
  24.         speedX = Input.GetAxisRaw("Horizontal") * movSpeed;
  25.         speedY = Input.GetAxisRaw("Vertical") * movSpeed;
  26.         rb.velocity = new Vector2(speedX, speedY);
  27.  
  28.  
  29.     }
  30. }



  • Recent Pastes