First project upload
This commit is contained in:
44
Assets/New Lowpoly Models/Scripts/CashBag.cs
Normal file
44
Assets/New Lowpoly Models/Scripts/CashBag.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user