Files
PIM_Laba2/Assets/_Scripts/Collectible.cs
T
2026-05-25 20:45:05 +03:00

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);
}
}
}