44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class CashBag : MonoBehaviour
|
|
{
|
|
[Header("Cash Range")]
|
|
[SerializeField] private int minCash = 50;
|
|
[SerializeField] private int maxCash = 200;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
Debug.Log("TRIGGERED BY: " + other.name);
|
|
|
|
if (other.CompareTag("Player") || other.CompareTag("Enemy"))
|
|
{
|
|
CashManager cash = other.GetComponentInParent<CashManager>();
|
|
|
|
if (cash != null)
|
|
{
|
|
Debug.Log("FOUND CashManager on: " + cash.gameObject.name);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("NO CashManager on: " + other.name);
|
|
}
|
|
|
|
if (cash != null)
|
|
{
|
|
int randomAmount = Random.Range(minCash, maxCash + 1);
|
|
cash.AddCash(randomAmount);
|
|
|
|
Debug.Log("Picked Cash: $" + randomAmount);
|
|
}
|
|
|
|
PlayerControllerNewRohan player = other.GetComponent<PlayerControllerNewRohan>();
|
|
|
|
if (player != null)
|
|
{
|
|
player.PlayPickupAnimation();
|
|
}
|
|
|
|
Destroy(gameObject); // ALWAYS destroy
|
|
}
|
|
}
|
|
} |