using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { public float moveSpeed = 5f; public float jumpForce = 7f; public Transform groundCheck; public LayerMask groundLayer; private Rigidbody2D rb; private bool isGrounded; private float groundCheckRadius = 0.2f; private float moveInput; void Start() { rb = GetComponent(); } void Update() { moveInput = Input.GetAxis("Horizontal"); // A/D tai nuolinäppäimet isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, groundLayer); // Liikkuminen rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y); // Hyppääminen if (isGrounded && Input.GetKeyDown(KeyCode.Space)) { rb.velocity = new Vector2(rb.velocity.x, jumpForce); } } }