Advertisement
katubug

Untitled

Jan 16th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using Player;
  2. using UnityEngine;
  3. using UnityEngine.InputSystem;
  4.  
  5. public class Collector : MonoBehaviour
  6. {
  7. PlayerInput _playerInput;
  8. bool _isInteractPressed;
  9.  
  10. private void Awake()
  11. {
  12. _playerInput = new PlayerInput();
  13. _playerInput.Enable();
  14.  
  15. _playerInput.CharacterControls.Interact.started += onGather;
  16. _playerInput.CharacterControls.Interact.canceled += onGather;
  17. }
  18.  
  19. void onGather(InputAction.CallbackContext context)
  20. {
  21. _isInteractPressed = context.ReadValueAsButton();
  22. Debug.Log($"{_isInteractPressed}"); //this works
  23. }
  24. private void OnTriggerEnter(Collider other)
  25. {
  26. ICollectible collectible = other.GetComponent<ICollectible>();
  27. if (collectible != null)
  28. {
  29. Debug.Log("colliding with collectible"); // this works
  30. }
  31.  
  32. if (collectible != null && _isInteractPressed)
  33. {
  34. Debug.Log("attempting to collect"); // this does NOT work
  35. collectible.Collect();
  36. }
  37. }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement