39 lines
910 B
C#
39 lines
910 B
C#
using UnityEngine;
|
|
|
|
public class ShopItem : MonoBehaviour
|
|
{
|
|
public ShopItemData data; // Assign in prefab
|
|
|
|
public float health = 100f; // Per-instance
|
|
public int currentStock = 1; // Per-instance
|
|
|
|
public bool NeedsReplacement => health < 40f;
|
|
|
|
public void ApplyDamage(float damage)
|
|
{
|
|
health -= damage;
|
|
CheckCondition();
|
|
}
|
|
|
|
public void GradualDecay(float decayRate)
|
|
{
|
|
if (data.perishable)
|
|
{
|
|
health -= decayRate;
|
|
CheckCondition();
|
|
}
|
|
}
|
|
|
|
void CheckCondition()
|
|
{
|
|
if (health <= 0)
|
|
{
|
|
GeneralUIController.Instance.ShowMessage($"💥 {data.itemName} is ruined! Removing...");
|
|
Destroy(gameObject);
|
|
}
|
|
else if (health < 40)
|
|
{
|
|
GeneralUIController.Instance.ShowMessage($"⚠️ {data.itemName} is in poor condition!");
|
|
}
|
|
}
|
|
} |