using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement2D : MonoBehaviour { public float speed = 5f; public float jumpForce = 10f; private Rigidbody2D rb; private bool isGrounded; void Start() { rb = GetComponent(); } void Update() { // Bewegung float move = Input.GetAxis("Horizontal"); rb.velocity = new Vector2(move * speed, rb.velocity.y); // Springen if (Input.GetButtonDown("Jump") && isGrounded) { rb.velocity = new Vector2(rb.velocity.x, jumpForce); } } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Ground")) { isGrounded = true; } } private void OnCollisionExit2D(Collision2D collision) { if (collision.gameObject.CompareTag("Ground")) { isGrounded = false; } } }