You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
884 B
C#
28 lines
884 B
C#
2 months ago
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace D2D.Gameplay
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Can be expanded to: pick only when space bar pressed (for items)
|
||
|
/// </summary>
|
||
|
public class CollectablesPicker : MonoBehaviour
|
||
|
{
|
||
|
public event Action<GameObject> Picked;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 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.
|
||
|
/// </summary>
|
||
|
private void OnTriggerEnter(Collider other)
|
||
|
{
|
||
|
var collectable = other.GetComponent<ICollectable>();
|
||
|
if (collectable != null && !collectable.IsPicked)
|
||
|
{
|
||
|
collectable.Pick(owner: gameObject);
|
||
|
Picked?.Invoke(gameObject);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|