35 lines
883 B
C#
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();
|
|
}
|
|
}
|
|
} |