using System; using UnityEngine; namespace D2D.Gameplay { /// /// Can be expanded to: pick only when space bar pressed (for items) /// public class CollectablesPicker : MonoBehaviour { public event Action Picked; /// /// Yeah, we could make calling Pick inside of Collectable with it own OnTriggerEnter /// method, but to avoid invalid OnTriggerEnter call order we do all stuff inside this /// small picker class. /// private void OnTriggerEnter(Collider other) { var collectable = other.GetComponent(); if (collectable != null && !collectable.IsPicked) { collectable.Pick(owner: gameObject); Picked?.Invoke(gameObject); } } } }