Unity nowy Input System

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    Rigidbody2D rb;
    float dir;
    float speed = 5f;
    float jumpPower = 10f;

    private void Awake() => rb = GetComponent<Rigidbody2D>();

    void FixedUpdate()
    {
        rb.velocity = new Vector2(dir * speed, rb.velocity.y);
    }

    public void Move(InputAction.CallbackContext value)
    {
        dir = value.ReadValue<Vector2>().x;
    }

    public void Jump(InputAction.CallbackContext value)
    {
        if (value.performed)
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpPower);
        }
    }
}
Scroll to Top