ChrisTutorials

MoneyPickup.cs

Jan 9th, 2022 (edited)
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoneyPickup : MonoBehaviour
  6. {
  7.     public int cashValue = 1;
  8.  
  9.     private void OnTriggerEnter2D(Collider2D other) {
  10.         if(other.tag == "Player") {
  11.             IInventory inventory = other.GetComponent<IInventory>();
  12.  
  13.             if(inventory != null){
  14.                 inventory.Money = inventory.Money + cashValue;
  15.                 print("Player inventory has " + inventory.Money + " money in it.");
  16.                 gameObject.SetActive(false);
  17.             }
  18.         }
  19.     }
  20. }
  21.  
Add Comment
Please, Sign In to add comment