Advertisement
katubug

interact not working

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