update level1
This commit is contained in:
@@ -16,12 +16,16 @@ public class CharacterController2D : MonoBehaviour
|
||||
[SerializeField]
|
||||
private Transform _groundCheckTransformB;
|
||||
|
||||
[SerializeField]
|
||||
private Animator _animator;
|
||||
|
||||
private Rigidbody2D _rigidBody;
|
||||
private InputAction _moveAction;
|
||||
private InputAction _jumpAction;
|
||||
|
||||
private Vector2 _moveInput;
|
||||
private bool _isGrounded;
|
||||
private bool _isFlipped;
|
||||
|
||||
private PlayerInput _playerInput;
|
||||
|
||||
@@ -69,11 +73,24 @@ public class CharacterController2D : MonoBehaviour
|
||||
private void OnMovePerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
_moveInput = context.ReadValue<Vector2>();
|
||||
if (_moveInput.x < 0 && !_isFlipped)
|
||||
{
|
||||
_isFlipped = true;
|
||||
transform.localScale = new Vector3(-1.0f * transform.localScale.x, transform.localScale.y, transform.localScale.z);
|
||||
}
|
||||
else if (_moveInput.x > 0 && _isFlipped)
|
||||
{
|
||||
_isFlipped = false;
|
||||
transform.localScale = new Vector3(-1.0f * transform.localScale.x, transform.localScale.y, transform.localScale.z);
|
||||
}
|
||||
|
||||
_animator.SetBool("MoveX", true);
|
||||
}
|
||||
|
||||
private void OnMoveCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
_moveInput = Vector2.zero;
|
||||
_animator.SetBool("MoveX", false);
|
||||
}
|
||||
|
||||
private void OnJumpPerformed(InputAction.CallbackContext context)
|
||||
@@ -81,12 +98,14 @@ public class CharacterController2D : MonoBehaviour
|
||||
if (_isGrounded)
|
||||
{
|
||||
_rigidBody.AddForce(Vector2.up * _jumpForce, ForceMode2D.Impulse);
|
||||
_animator.SetTrigger("Jump");
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
_isGrounded = Physics2D.OverlapArea(_groundCheckTransformA.position, _groundCheckTransformB.position, _groundLayer);
|
||||
_animator.SetBool("Falling", !_isGrounded);
|
||||
|
||||
if (_isGrounded)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user