WEBLEB
Inicio
Editora de código
Iniciar sesión
Pro
Español
English
Français
Español
metro
9
DMARD21@christway.vic.edu.au
Abrir en el editor
Publica tu código
0
Recomendado
25 November 2025
Surfista del metro
3 March 2024
Cronómetro código html
HTML
Copy
csharpusing UnityEngine; public class PlayerMovement : MonoBehaviour { // Physics parameters public float moveSpeed = 8f; public float jumpForce = 12f; // State variables private float horizontalInput; private bool isGrounded; // Component references public Rigidbody2D rb; public Transform groundCheck; public LayerMask groundLayer; void Update() { // Get left/right input (A/D or Arrow keys) horizontalInput = Input.GetAxisRaw("Horizontal"); // Check if player is touching the ground layer isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer); // Jump trigger if (Input.GetButtonDown("Jump") && isGrounded) { rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); } } void FixedUpdate() { // Apply left/right velocity safely in physics step rb.linearVelocity = new Vector2(horizontalInput * moveSpeed, rb.linearVe
CSS
Copy
<!-- Replace with your CSS Code (Leave empty if not needed) -->
JS
Copy
/* Replace with your JS Code (Leave empty if not needed) */