using System.Collections; using System.Collections.Generic; using UnityEngine; public class HealthPickUp : MonoBehaviour { public int healthRestored = 10; AudioSource pickupSource; private void Awake() { pickupSource = GetComponent(); } private void OnTriggerEnter2D(Collider2D collision) { Damageable damageable = collision.GetComponent(); if (damageable) { bool wasHealed = damageable.Heal(healthRestored); if (wasHealed) { if (pickupSource) { AudioSource.PlayClipAtPoint(pickupSource.clip, gameObject.transform.position, pickupSource.volume); } Destroy(gameObject); } } } }