Advertisement
Guest User

PlayerInventory

a guest
Apr 6th, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Diagnostics;
  5.  
  6. public class PlayerInventory : MonoBehaviour
  7. {
  8.     public delegate void PickupAction(InventoryObject _inventory);
  9.     public static event PickupAction OnItemPickedUp;
  10.     public InventoryObject inventory;
  11.     // Start is called before the first frame update
  12.     public void Start()
  13.     {
  14.        
  15.     }
  16.     public void OnTriggerEnter2D(Collider2D other)
  17.     {
  18.        var item = other.GetComponent<renderItemSprite>().equipment;
  19.         if (item)
  20.         {
  21.             UnityEngine.Debug.Log("Player-Item collision!");
  22.             inventory.AddItem(item, 1);
  23.             Destroy(other.gameObject);
  24.             if(OnItemPickedUp != null)
  25.             {
  26.                     OnItemPickedUp(inventory);
  27.                      UnityEngine. Debug.Log("Item Pickup Event Raised!");
  28.             }
  29.  
  30.         }
  31.        
  32.     }
  33.    
  34.     private void OnApplicationQuit()
  35.     {
  36.         inventory.Container.Clear();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement