using UnityEngine;

public class HealController : MonoBehaviour
{
    public GameObject manager;
    public float heal = 1f;

    // Links to the ScoreManager on start
    private void Start()
    {
        if (manager == null)
        {
            manager = GameObject.FindGameObjectsWithTag("GameManager")[0];
        }
    }

    // Triggers when the point is touched
    void OnTriggerEnter2D(Collider2D other)
    {
        healCollected();
    }

    // Notifies the manager that point was collected and destroys itself
    public void healCollected()
    {
        if (manager != null) manager.GetComponent<HealthManager>().addHealth(heal);
        Object.Destroy(gameObject);
    }
}
