
Invoke Unity Event 사용
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
private Vector2 moveDirection;
[SerializeField]
private float moveSpeed = 4f;
void Update()
{
if (moveDirection != Vector2.zero)
{
transform.Translate(new Vector3(moveDirection.x, moveDirection.y, 0) * moveSpeed * Time.deltaTime);
}
}
public void OnMove(InputAction.CallbackContext context)
{
moveDirection = context.ReadValue<Vector2>();
if (moveDirection != Vector2.zero)
{
Debug.Log($"UNITY_EVENTS : {moveDirection.magnitude}");
}
}
public void OnInteraction(InputAction.CallbackContext context)
{
if (context.performed)
{
// 상호작용 로직
Debug.Log("상호작용");
}
}
}
접근 제한자 public에 유의