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 CoinPickup : MonoBehaviour { AudioManager audioManager; // Reference to the audio manager void Awake() { // Initialize audio manager audioManager = GameObject.FindGameObjectWithTag("Audio").GetComponent(); } void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { // Increment the coin count and save it to PlayerPrefs int coinCount = PlayerPrefs.GetInt("CoinCount", 0); coinCount++; PlayerPrefs.SetInt("CoinCount", coinCount); // Optionally, play a sound or animation here audioManager.PlaySFX(audioManager.coinSFX); Destroy(gameObject); // Remove the coin object } } }