rabidus-test/Assets/Scripts/BaseItem.cs

31 lines
639 B
C#

using UnityEngine;
using UnityEngine.Events;
public class BaseItem : MonoBehaviour, IInteractable
{
[SerializeField]
private float _scoreAdd = 0;
[SerializeField]
private bool _selfDestroy = true;
protected ScoreController _scoreController;
public UnityEvent OnInterract;
protected virtual void Awake()
{
_scoreController = FindObjectOfType<ScoreController>();
}
public virtual void Interact()
{
OnInterract?.Invoke();
if (_scoreAdd > 0)
_scoreController.AddScore(_scoreAdd, true);
if (_selfDestroy)
Destroy(gameObject);
}
}