Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Player;
- using UnityEngine;
- using UnityEngine.InputSystem;
- public class Collector : MonoBehaviour
- {
- PlayerInput _playerInput;
- bool _isInteractPressed;
- private void Awake()
- {
- _playerInput = new PlayerInput();
- _playerInput.Enable();
- _playerInput.CharacterControls.Interact.started += onGather;
- _playerInput.CharacterControls.Interact.canceled += onGather;
- }
- void onGather(InputAction.CallbackContext context)
- {
- _isInteractPressed = context.ReadValueAsButton();
- Debug.Log($"{_isInteractPressed}"); //this works
- }
- private void OnTriggerEnter(Collider other)
- {
- ICollectible collectible = other.GetComponent<ICollectible>();
- if (collectible != null)
- {
- Debug.Log("colliding with collectible"); // this works
- }
- if (collectible != null && _isInteractPressed)
- {
- Debug.Log("attempting to collect"); // this does NOT work
- collectible.Collect();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement