2023-08-15 17:38:54 +03:00
|
|
|
|
using UnityEngine;
|
2023-10-09 16:51:27 +03:00
|
|
|
|
using UnityEngine.Events;
|
2023-08-15 17:38:54 +03:00
|
|
|
|
|
|
|
|
|
public class BaseItem : MonoBehaviour, IInteractable
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float _scoreAdd = 0;
|
2023-09-11 15:44:17 +03:00
|
|
|
|
[SerializeField]
|
|
|
|
|
private bool _selfDestroy = true;
|
2023-08-15 17:38:54 +03:00
|
|
|
|
|
2023-08-22 15:41:12 +03:00
|
|
|
|
protected ScoreController _scoreController;
|
|
|
|
|
|
2023-10-09 16:51:27 +03:00
|
|
|
|
public UnityEvent OnInterract;
|
|
|
|
|
|
2023-08-22 15:41:12 +03:00
|
|
|
|
protected virtual void Awake()
|
|
|
|
|
{
|
|
|
|
|
_scoreController = FindObjectOfType<ScoreController>();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 17:38:54 +03:00
|
|
|
|
public virtual void Interact()
|
|
|
|
|
{
|
2023-10-09 16:51:27 +03:00
|
|
|
|
OnInterract?.Invoke();
|
|
|
|
|
|
2023-08-22 15:41:12 +03:00
|
|
|
|
if (_scoreAdd > 0)
|
|
|
|
|
_scoreController.AddScore(_scoreAdd, true);
|
|
|
|
|
|
2023-09-11 15:44:17 +03:00
|
|
|
|
if (_selfDestroy)
|
|
|
|
|
Destroy(gameObject);
|
2023-08-15 17:38:54 +03:00
|
|
|
|
}
|
|
|
|
|
}
|