Blend Tree 를 이용한 Input System
2024. 1. 29. 20:24ㆍ개인적인 공부/Unity
using System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[Header("Config")]
[SerializeField] private float speed;
private readonly int moveX = Animator.StringToHash("MoveX");
private readonly int moveY = Animator.StringToHash("MoveY");
private PlayerActions actions;
private Rigidbody2D rb2D;
private Animator animator;
private Vector2 moveDirection;
private void Awake()
{
actions = new PlayerActions();
animator = GetComponent<Animator>();
rb2D = GetComponent<Rigidbody2D>();
}
private void Update()
{
ReadMovement();
}
private void FixedUpdate()
{
Move();
}
private void Move()
{
rb2D.MovePosition(rb2D.position + moveDirection * (speed * Time.fixedDeltaTime));
}
private void ReadMovement()
{
moveDirection = actions.Movement.Move.ReadValue<Vector2>().normalized;
if (moveDirection == Vector2.zero) return;
animator.SetFloat(moveX, moveDirection.x);
animator.SetFloat(moveY, moveDirection.y);
}
private void OnEnable()
{
actions.Enable();
}
private void OnDisable()
{
actions.Disable();
}
}
'개인적인 공부 > Unity' 카테고리의 다른 글
URP2D (0) | 2025.04.28 |
---|---|
EditorWindow (0) | 2023.09.12 |
Health Slider issue (0) | 2023.09.06 |
Remote Play 확인 (0) | 2023.08.22 |
GamePad Attack (0) | 2023.08.16 |