플랫폼별 입력 화장성을 위해 Inputs구조체 추가 및 InputControoller 추가
- 캐릭터 이동이 정상적으로 작동하지 않는 문제 수정
This commit is contained in:
@@ -1,5 +1,24 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.PlayerLoop;
|
||||
|
||||
public struct Inputs
|
||||
{
|
||||
public bool Jump;
|
||||
public Vector2 Move;
|
||||
public bool Attack;
|
||||
}
|
||||
|
||||
public class InputController
|
||||
{
|
||||
public static void UpdateInput(ref Inputs inputs)
|
||||
{
|
||||
inputs.Jump = Input.GetButtonDown("Jump");
|
||||
inputs.Move.x = Input.GetAxisRaw("Horizontal");
|
||||
inputs.Attack = Input.GetMouseButtonDown(0);
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
// 컴포넌트 프로퍼티
|
||||
@@ -10,6 +29,10 @@ public class PlayerMove : MonoBehaviour
|
||||
public float maxSpeed;
|
||||
public float jumpPower;
|
||||
|
||||
private Inputs _inputs;
|
||||
|
||||
public Inputs Inputs => _inputs;
|
||||
|
||||
// 변수
|
||||
[SerializeField]
|
||||
public int hp = 5;
|
||||
@@ -30,7 +53,7 @@ public class PlayerMove : MonoBehaviour
|
||||
// Null 체크 추가
|
||||
if (RigidBody == null || SpriteRenderer == null || Animator == null)
|
||||
{
|
||||
Debug.LogError("PlayerMove script requires Rigidbody2D, SpriteRenderer, and Animator components on the same GameObject.");
|
||||
Debug.LogError("PlayerMove 스크립트에는 동일한 GameObject에 Rigidbody2D, SpriteRenderer 및 Animator 구성 요소가 필요합니다.");
|
||||
// 게임 오브젝트 비활성화 또는 스크립트 비활성화
|
||||
enabled = false;
|
||||
return;
|
||||
@@ -52,18 +75,20 @@ public class PlayerMove : MonoBehaviour
|
||||
|
||||
if (attackCollider == null)
|
||||
{
|
||||
Debug.LogError("AttackArea child object or Collider2D component not found!");
|
||||
Debug.LogError("AttackArea 자식 객체나 Collider2D 구성 요소를 찾을 수 없습니다!");
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// 모든 입력값을 매 프레임 업데이트
|
||||
InputController.UpdateInput(ref _inputs);
|
||||
// 상태 머신 업데이트
|
||||
_stateMachine.Update();
|
||||
|
||||
// 프레임이 끝난 후, 다음 프레임을 위해 "GetButtonDown"으로 받는 입력들은 리셋( Jump와 Attack )
|
||||
_inputs.Jump = false;
|
||||
_inputs.Attack = false;
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
|
||||
Reference in New Issue
Block a user