관리 메뉴

STIKA-DEV

TIL[38] 본문

프로그래밍/Unity + C#

TIL[38]

STIKA 2024. 3. 7. 16:22

24.03.07 Thu

 

 

❤️ TIL [38]

Today I Learned


✏️ 작업 내용

✔️ PlayerInputSystem -> Unity Event 방식

✔️ NewInputSystem - Button / tab, slowtab


✔️ PlayerInputSystem -> Unity Event 방식

3D 자료는 많은데 2D자료가 모자라서 유튜브 참고

public class PlayerMovement : MonoBehaviour
{
    public float speed = 300f;
    private Vector2 _movement;

    private Rigidbody2D _rigidbody;

    private void Awake()
    {
        _rigidbody = GetComponent<Rigidbody2D>();
    }

    private void FixedUpdate()
    {
        if (_movement != null)
        {
            _rigidbody.velocity = _movement * speed * Time.deltaTime;
            Debug.Log(_movement * speed * Time.deltaTime);
        }
    }

    public void OnMovement(InputAction.CallbackContext context)
    {
        if (_movement != null)
        {
            _movement = context.ReadValue<Vector2>();
        }
    }
}

✔️ NewInputSystem - Button / tab, slowtab

	public void OnJump(InputAction.CallbackContext context)
    {
        switch (context.phase)
        {
            case InputActionPhase.Performed:
                if (_movement.x == 0f || _movement.y == 0f)
                    this.transform.position += (Vector3)_movement * 1f;
                Debug.Log("탭성공");
                break;
            case InputActionPhase.Started:
                Debug.Log("눌림");
                break;
            case InputActionPhase.Canceled:
                Debug.Log("탭실패");
                break;
        }
        //슬로우탭은 0.5초이상눌러야 성공
        //탭은 0.2초이하로 눌러야 성공
        //현재 스페이스바에 탭만 걸어둠
    }

 

 

 

 


📝 오늘의 마무리

 


 

✏️ 스스로 어제보다 한 발 더 나아갔다는 것을 자각하기

✏️ TIL을 쓰기 위해서라도, 오늘 반드시 단 하나라도 배우기

✏️ 꾸준히 기록을 남기는 습관 가지기

'프로그래밍 > Unity + C#' 카테고리의 다른 글

TIL[40]✏️  (0) 2024.03.09
TIL[39]  (0) 2024.03.08
TIL[37] < 새로운 팀 프로젝트 시작 >  (0) 2024.03.07
TIL[36]  (0) 2024.02.28
TIL[35]  (0) 2024.02.27