Script to change a Sprite to another

This is part of my script, but it doesn’t work in gameplay when I call this method the hearts are still there without showing any change

void UpdateHearts()
{
    if (data.Lives == 3)
    {
        ui.heart1.sprite = ui.fullHeart;
        ui.heart2.sprite = ui.fullHeart;
        ui.heart3.sprite = ui.fullHeart;
    }

    if (data.Lives==2)
    {
        ui.heart1.sprite = ui.emptyHeart;
    }

    if (data.Lives == 1)
    {
        ui.heart2.sprite = ui.emptyHeart;
        ui.heart1.sprite = ui.emptyHeart;
    }
}

hi;
the problem can be any where from scripts to editors;
u have to debug these kind of problems step by step i cant help u here like this;

u may log the “Lives” or the times that function “UpdateHearts” is calling or check the editor to see if another image is not showing in front or etc …