You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RatAttack2D/Assets/Scripts/PlayerMovement.cs

48 lines
1.1 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody2D rb;
private Inputs Input;
private InputAction Walk;
private InputAction Jump;
private InputAction Dash;
private Vector2 Force;
public float Speed;
private void Awake()
{
Input = new Inputs();
rb = this.gameObject.GetComponent<Rigidbody2D>();
}
private void OnEnable()
{
Walk = Input.Movement.wasd;
Jump = Input.Movement.Jump;
Dash = Input.Movement.Dash;
Walk.Enable();
Jump.Enable();
Dash.Enable();
}
private void OnDisable()
{
Walk.Disable();
Jump.Disable();
Dash.Disable();
}
// Start is called before the first frame update
private void Start()
{
}
// Update is called once per frame
private void Update()
{
Force = Walk.ReadValue<Vector2>();
rb.AddForce(new Vector2(Force.x * Speed * Time.deltaTime, 0), ForceMode2D.Impulse);
}
}