katubug

Untitled

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