Health:Index was outside the bounds of the array

If my Player has 1 Heart and something hits him with more than 1 dmg the game crashes. Example Player has 4 Hearts I touch enemy -1 Health, touch spikes -4 health. Crash. Im still new to this.

Hud:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HUD : MonoBehaviour
{

public Sprite[] HeartSprites;

public Image HeartUI;

private Player player;

void Start()
{

    player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();

}

void Update()
{

    HeartUI.sprite = HeartSprites[player.curHealth];

}

}

Player

void Die()
{
    Application.LoadLevel(Application.loadedLevel);
}

public void Damage(int dmg)
{
    curHealth -= dmg;
}

Spikes

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spikes : MonoBehaviour
{
private Player player;

void Start()
{
    player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
}

void OnTriggerEnter2D(Collider2D collision)
{
    if (collision.CompareTag("Player"))
    {
        player.Damage(4);
    }
}

}

Enemy(name is Gurdo grunt)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GurdoGruntTrigger : MonoBehaviour
{
private Player player;

void Start()
{
    player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
}

void OnTriggerEnter2D(Collider2D collision)
{
    if (collision.CompareTag("Player"))
    {
        player.Damage(1);
    }
}

}

If the player has negative health, it tries to get the sprite from a negative index. If the player has 1 health, it will get the 2nd sprite in the array, because the first index is 0. I assume the first sprite in the array isn’t for when the player is dead at 0 health.

Change
HeartUI.sprite = HeartSprites[player.curHealth];
To
HeartUI.sprite = HeartSprites[Mathf.Max(0, player.curHealth - 1)];

Thank you! That worked!