using System.Collections; using System.Collections.Generic; using UnityEngine; public class Potion : MonoBehaviour { // Pick up sfx [SerializeField] AudioClip pickupFX; // Components AudioSource audioSource; SpriteRenderer spriteRenderer; // Method runs on first frame void Start() { // Getting components audioSource = GetComponent(); spriteRenderer = GetComponent(); } // If something enters the potion trigger void OnTriggerEnter2D(Collider2D col) { // If player enters the cauldron trigger if (col.gameObject.tag == "Player") { // Play pickup sfx, start waitforfx coroutine and hide the cauldron audioSource.PlayOneShot(pickupFX); StartCoroutine(WaitForFX()); spriteRenderer.enabled = false; } } // Coroutine that waits for the sfx to play before destorying itself IEnumerator WaitForFX() { yield return new WaitForSeconds(0.8f); Destroy(gameObject); } }