/* * ------------------------------------------------------------------------ * Description: This class handles picking up stuff to go in inventory * Author: Eli Simpkins-Simmonds * ------------------------------------------------------------------------ */ using UnityEngine; public class PickupItem : MonoBehaviour { // This method is called when another collider enters the trigger collider attached to the object where this script is attached void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { // Get the Inventory component from the object that collided with the trigger Inventory inventory = other.GetComponent(); // If the Inventory component is found if (inventory != null) { // Call the CollectItem method on the Inventory component to update the inventory inventory.CollectItem(); // Destroy the game object this script is attached to, removing the item from the scene Destroy(gameObject); } } } }