Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Player;
- using System;
- using UnityEditor.PackageManager;
- using UnityEngine;
- using UnityEngine.InputSystem;
- public class Collector : MonoBehaviour
- {
- PlayerInput _playerInput;
- bool _isInteractPressed;
- bool _isCollectibleCollided;
- 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();
- if (_isCollectibleCollided && _isInteractPressed)
- {
- Debug.Log("attempting to collect");
- collectible.Collect();
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- ICollectible collectible = other.GetComponent<ICollectible>();
- if (collectible != null)
- {
- _isCollectibleCollided = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment