완
This commit is contained in:
@@ -1,16 +1,38 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
public float moveSpeed;
|
||||
public float jumpForce;
|
||||
|
||||
private Rigidbody2D _rb;
|
||||
private UnicornInputSystem _unicorn;
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_unicorn.Player.Jump.performed -= Jump;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
_unicorn = UnicornInput.Unicorn;
|
||||
_unicorn.Player.Jump.performed += Jump;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
|
||||
|
||||
private void Jump(InputAction.CallbackContext obj)
|
||||
{
|
||||
|
||||
_rb.linearVelocityY = jumpForce;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
var readValue = _unicorn.Player.Horizontal.ReadValue<float>();
|
||||
_rb.linearVelocityX = readValue * moveSpeed;
|
||||
if (_unicorn.Player.Down.IsPressed() && _rb.linearVelocityY < jumpForce/1.5)
|
||||
_rb.linearVelocityY = Math.Min(0, _rb.linearVelocityY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user