59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PilihSkinMenu : MonoBehaviour
|
|
{
|
|
[Header("Daftar Tombol & Kartu")]
|
|
public Button[] tombolKlik; // Tombol besar yang buat diklik
|
|
public Image[] gambarTombolKecil; // Gambar "Pakai/Lepas" yang di bawah kaki
|
|
public Image[] kartuSkinBesar; // BARU: Tarik 4 gambar kartu skin besarmu ke sini
|
|
|
|
[Header("Desain Tombol")]
|
|
public Sprite spriteHijauPakai;
|
|
public Sprite spriteAbuLepas;
|
|
|
|
void OnEnable() { RefreshTampilan(); }
|
|
|
|
public void RefreshTampilan()
|
|
{
|
|
int skinAktif = PlayerPrefs.GetInt("SkinDipakai", 0);
|
|
|
|
for (int i = 0; i < tombolKlik.Length; i++)
|
|
{
|
|
// PENGAMAN: Cek jumlah slot biar nggak error merah
|
|
if (i >= gambarTombolKecil.Length || i >= kartuSkinBesar.Length) break;
|
|
|
|
// Cek status Unlock (Dino selalu terbuka)
|
|
bool isUnlocked = (i == 0) || (PlayerPrefs.GetInt("SkinUnlocked_" + i, 0) == 1);
|
|
|
|
if (isUnlocked)
|
|
{
|
|
// --- KONDISI: SKIN TERBUKA ---
|
|
tombolKlik[i].interactable = true;
|
|
gambarTombolKecil[i].sprite = (i == skinAktif) ? spriteHijauPakai : spriteAbuLepas;
|
|
|
|
// Warnanya jadi CERAH
|
|
gambarTombolKecil[i].color = Color.white;
|
|
kartuSkinBesar[i].color = Color.white;
|
|
}
|
|
else
|
|
{
|
|
// --- KONDISI: SKIN TERKUNCI ---
|
|
tombolKlik[i].interactable = false;
|
|
gambarTombolKecil[i].sprite = spriteAbuLepas;
|
|
|
|
// Warnanya jadi GELAP (Redup)
|
|
Color warnaRedup = new Color(0.3f, 0.3f, 0.3f, 0.7f); // Abu-abu gelap transparan
|
|
gambarTombolKecil[i].color = warnaRedup;
|
|
kartuSkinBesar[i].color = warnaRedup;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void KlikPilihSkin(int id)
|
|
{
|
|
PlayerPrefs.SetInt("SkinDipakai", id);
|
|
PlayerPrefs.Save();
|
|
RefreshTampilan();
|
|
}
|
|
} |