/* * ------------------------------------------------------------------------ * Description: This class handles inventory collection system * Author: Eli Simpkins-Simmonds * ------------------------------------------------------------------------ */ using UnityEngine; public class Inventory : MonoBehaviour { public int itemsCollected = 0; // Tracks the number of items collected by the player public UIManager uiManager; // Reference to the UIManager script to update the UI public int totalItemsRequired = 5; // The total number of items required to open the doors private Door[] doors; // Array to store all door objects in the scene void Start() { uiManager = FindObjectOfType(); // Find the UIManager in the scene doors = FindObjectsOfType(); // Find all door objects in the scene } public void CollectItem() { itemsCollected++; // Increment the number of items collected Debug.Log("Items Collected: " + itemsCollected); // Log the current number of items collected uiManager.UpdateLoadingBar(itemsCollected); // Update the UI loading bar if (itemsCollected >= totalItemsRequired) // Check if the required number of items is collected { OpenAllDoors(); // Open all doors if the required number of items is collected } } private void OpenAllDoors() { foreach (Door door in doors) // Iterate through each door in the array { door.OpenDoor(); // Open the door } } public void ResetInventory() { itemsCollected = 0; // Reset the number of items collected to zero uiManager.ResetLoadingBar(); // Reset the UI loading bar foreach (Door door in doors) // Iterate through each door in the array { door.CloseDoor(); // Close the door } } }