33 lines
696 B
C#
33 lines
696 B
C#
using UnityEngine;
|
|
|
|
public class Collectible : MonoBehaviour
|
|
{
|
|
[SerializeField] private int scoreValue = 1;
|
|
[SerializeField] private bool destroyOnPickup = true;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!other.CompareTag("Player"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
UIManager uiManager = FindObjectOfType<UIManager>();
|
|
if (uiManager != null)
|
|
{
|
|
uiManager.AddScore(scoreValue);
|
|
}
|
|
|
|
Debug.Log($"Collected {name} for {scoreValue} point(s).");
|
|
|
|
if (destroyOnPickup)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
else
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|