using System.Collections; using System.Collections.Generic; using UnityEngine; public class CoinPickup : MonoBehaviour { private AudioSource audioSource; ReplayScreen replayScreen; [SerializeField] int pointsForCoinPickup = 1; void Start() { // Get the AudioSource component attached to the coin audioSource = GetComponent(); } void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { // Play the coin sound audioSource.Play(); // Add score FindObjectOfType().AddToScore(pointsForCoinPickup); // Disable the coin's visuals and collider while the sound plays GetComponent().enabled = false; GetComponent().enabled = false; // Destroy the coin after the audio finishes playing Destroy(gameObject, audioSource.clip.length); } } }