31 lines
782 B
C#
Raw Permalink Normal View History

2025-07-30 01:38:12 +05:00
using UnityEngine;
2025-09-11 18:46:20 +05:00
[RequireComponent(typeof(Collider))]
2025-07-30 01:38:12 +05:00
public class ChaseCoin : MonoBehaviour
{
public int coinValue = 1;
2025-09-11 18:46:20 +05:00
private void Reset()
2025-07-30 01:38:12 +05:00
{
2025-09-11 18:46:20 +05:00
// ensure trigger
var col = GetComponent<Collider>();
if (col) col.isTrigger = true;
}
private void OnTriggerEnter(Collider other)
{
if (!other.CompareTag("Player")) return;
// 1) Spawn VFX via ancestor spawner (works even if the adder is many parents up)
var vfxAdder = GetComponentInParent<CoinVFXAdder>();
if (vfxAdder) vfxAdder.SpawnAt(transform);
// 2) Score
var scoreMgr = FindObjectOfType<ChaseScoreManager>();
if (scoreMgr) scoreMgr.AddScore(coinValue);
2025-07-30 01:38:12 +05:00
2025-09-11 18:46:20 +05:00
// 3) Destroy coin
Destroy(gameObject);
2025-07-30 01:38:12 +05:00
}
}