using Firebase.Database; using UnityEngine; using UnityEngine.UI; public class QuizManager : MonoBehaviour { public Text QuizScoreText; private string userID; private DatabaseReference dbReference; [Header("Soal Settings")] public GameObject[] soals; // Tambahkan GameObject soal-soalnya via Inspector private int currentSoalIndex = 0; void Start() { // Ambil userID yang disimpan dari DatabaseManager userID = PlayerPrefs.GetString("UserID", ""); if (string.IsNullOrEmpty(userID)) { Debug.LogError("UserID tidak ditemukan! Pastikan scene DatabaseManager berjalan lebih dulu."); return; } dbReference = FirebaseDatabase.DefaultInstance.RootReference; // Hanya aktifkan soal pertama saat start for (int i = 0; i < soals.Length; i++) { soals[i].SetActive(i == 0); } } public void SaveQuizScore() { if (string.IsNullOrEmpty(QuizScoreText.text)) { Debug.LogError("Skor pretest tidak boleh kosong!"); return; } int QuizScore = int.Parse(QuizScoreText.text); // Simpan skor pretest di Firebase dengan userID yang benar dbReference.Child("users").Child(userID).Child("scores").Child("quizScore").SetValueAsync(QuizScore); Debug.Log("Skor pretest tersimpan untuk user: " + userID); } public void NextSoal() { if (currentSoalIndex < soals.Length - 1) { soals[currentSoalIndex].SetActive(false); currentSoalIndex++; soals[currentSoalIndex].SetActive(true); } else { Debug.Log("Semua soal sudah selesai!"); // Di sini kamu bisa panggil SaveQuizScore() otomatis atau tampilkan skor panel } } }