36 lines
984 B
C#
36 lines
984 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Code.Game.Minigames.MusicGame.UI
|
|
{
|
|
public class MusicMinigamePlayerHealth : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject heartPrefab;
|
|
|
|
private List<GameObject> _hearts = new();
|
|
|
|
// sbe
|
|
public void SetHealth(int count)
|
|
{
|
|
if (_hearts.Count < count)
|
|
for (; count > 0; count--)
|
|
_hearts.Add(Instantiate(heartPrefab, transform));
|
|
else if (count >= 0)
|
|
{
|
|
for (var toDelete = _hearts.Count - count; toDelete > 0; toDelete--)
|
|
{
|
|
Destroy(_hearts[toDelete - 1]);
|
|
_hearts.RemoveAt(toDelete - 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DecreaseHealth()
|
|
{
|
|
if (_hearts.Count <= 0) return;
|
|
|
|
Destroy(_hearts[0]);
|
|
_hearts.RemoveAt(0);
|
|
}
|
|
}
|
|
} |