MIF_E31222398/Assets/Script/HealthPickUp.cs

35 lines
812 B
C#

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