using System.Collections; using System.Collections.Generic; using UnityEngine; /* -------------------------------------- Project: Programing assessment Standard: 91906 (AS3.7) v.1 School: Tauranga Boys' College Author: Rauputu Noah Phizacklea Date: August 2024 Unity: 2021.3.18f --------------------------------------- */ public class Pickup : MonoBehaviour { private Inventory inventory; public GameObject itemButton; // UI button to represent the item in inventory AudioManager audioManager; // Reference to the audio manager public bool isHeart; // Flag to check if the item is a heart void Awake() { // Initialize audio manager audioManager = GameObject.FindGameObjectWithTag("Audio").GetComponent(); } void Start() { // Initialize the inventory reference inventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); } // Check for collisions with the player void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { if (isHeart) // Check if the pickup is a heart { PlayerHealth playerHealth = other.GetComponent(); if (playerHealth != null) { audioManager.PlaySFX(audioManager.healPickupSFX); playerHealth.ResetHealth(); // Restore the player's health to full } Destroy(gameObject); // Remove the heart pickup object } else { for (int i = 0; i < inventory.slots.Length; i++) { if (!inventory.isFull[i]) { // Add item to inventory and update UI inventory.isFull[i] = true; Instantiate(itemButton, inventory.slots[i].transform, false); Destroy(gameObject); // Remove the pickup object break; } } } } } }