Files
Two-World/Assets/Scripts/PlayerInteraction.cs
2025-05-08 09:24:43 +09:00

35 lines
883 B
C#

using UnityEngine;
using UnityEngine.InputSystem;
namespace Assets
{
[RequireComponent(typeof(PlayerInput))]
public class PlayerInteraction : MonoBehaviour
{
[SerializeField]
private WorldSwitcher _worldSwitcher;
private PlayerInput _playerInput;
private InputAction _interactAction;
private void Awake()
{
_playerInput = GetComponent<PlayerInput>();
_interactAction = _playerInput.actions["SwitchWorld"];
}
private void OnEnable()
{
if (_interactAction != null)
{
_interactAction.Enable();
_interactAction.performed += OnInteractPerformed;
}
}
private void OnInteractPerformed(InputAction.CallbackContext context)
{
_worldSwitcher.SwitchNext();
}
}
}