Files
dldydtn9755-crypto 07cc9267a8 컴퓨터 수정
2026-07-15 12:53:00 +09:00

46 lines
1.0 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class HeartAffectionUI : MonoBehaviour
{
[Header("채워지는 하트 10개")]
public Image[] fillHearts;
[Header("퍼센트 텍스트")]
public TMP_Text percentText;
[Header("호감도")]
[Range(0, 100)]
public int affectionPercent = 0;
private void Start()
{
SetAffection(affectionPercent);
}
public void SetAffection(int percent)
{
affectionPercent = Mathf.Clamp(percent, 0, 100);
// 11% = 1.1개 하트
// 45% = 4.5개 하트
// 78% = 7.8개 하트
float heartValue = affectionPercent / 10f;
for (int i = 0; i < fillHearts.Length; i++)
{
fillHearts[i].fillAmount = Mathf.Clamp01(heartValue - i);
}
if (percentText != null)
{
percentText.text = affectionPercent + "%";
}
}
public void AddAffection(int amount)
{
SetAffection(affectionPercent + amount);
}
}