// using System.Collections; // using System.Collections.Generic; // using UnityEngine; // public class kontrol : MonoBehaviour // { // public GameObject parent; // GameObject yang memiliki child // int urutan = 0; // Variabel untuk menyimpan urutan child yang aktif // // Start is called before the first frame update // void Start() // { // // Inisialisasi: Aktifkan child pertama // if (parent != null && parent.transform.childCount > 0) // { // parent.transform.GetChild(urutan).gameObject.SetActive(true); // } // } // // Method untuk mengaktifkan child berdasarkan urutan // void aktif(int a) // { // // Update urutan // urutan += a; // // Handle urutan agar tetap dalam rentang yang valid // if (urutan < 0) // { // urutan = parent.transform.childCount - 1; // } // else if (urutan >= parent.transform.childCount) // { // urutan = 0; // } // // Nonaktifkan semua child // for (int i = 0; i < parent.transform.childCount; i++) // { // parent.transform.GetChild(i).gameObject.SetActive(false); // } // // Aktifkan child sesuai urutan // parent.transform.GetChild(urutan).gameObject.SetActive(true); // Debug.Log("Child aktif: " + parent.transform.GetChild(urutan).name); // Debug.Log("Total child: " + parent.transform.childCount); // } // // Method yang dipanggil saat tombol mouse dilepas // void OnMouseUp() // { // if (gameObject.name == "next") // { // aktif(1); // Next // } // else // { // aktif(-1); // Previous // } // } // // Update is called once per frame // void Update() // { // // Kosongkan jika tidak diperlukan // } // } // using System.Collections; // using System.Collections.Generic; // using UnityEngine; // public class kontrol : MonoBehaviour // { // public GameObject parent; // GameObject yang punya child puzzle set // int urutan = 0; // index puzzle aktif sekarang // bool sedangPindah = false; // biar nggak pindah berulang-ulang // void Start() // { // // Aktifkan puzzle pertama // AktifkanPuzzle(urutan); // } // void Update() // { // if (urutan >= parent.transform.childCount) // return; // Transform currentPuzzle = parent.transform.GetChild(urutan); // // Cek apakah puzzle sekarang masih aktif dan belum selesai // if (currentPuzzle.gameObject.activeSelf) // { // feedback f = currentPuzzle.GetComponent(); // if (f != null && f.selesai) // { // // Nonaktifkan puzzle sekarang // currentPuzzle.gameObject.SetActive(false); // // Naikkan urutan ke puzzle berikutnya // urutan++; // // Aktifkan puzzle berikutnya kalau masih ada // if (urutan < parent.transform.childCount) // { // parent.transform.GetChild(urutan).gameObject.SetActive(true); // } // } // } // } // IEnumerator PindahPuzzleSetelahDelay(float delay) // { // yield return new WaitForSeconds(delay); // // Nonaktifkan puzzle sekarang // parent.transform.GetChild(urutan).gameObject.SetActive(false); // // Naikkan urutan dan aktifkan berikutnya // urutan++; // if (urutan < parent.transform.childCount) // { // AktifkanPuzzle(urutan); // sedangPindah = false; // } // else // { // Debug.Log("Semua puzzle selesai!"); // } // } // void AktifkanPuzzle(int index) // { // // Nonaktifkan semua dulu // for (int i = 0; i < parent.transform.childCount; i++) // { // parent.transform.GetChild(i).gameObject.SetActive(false); // } // // Aktifkan yang sesuai // parent.transform.GetChild(index).gameObject.SetActive(true); // Debug.Log("Puzzle ke-" + (index + 1) + " aktif"); // } // } using System.Collections; using System.Collections.Generic; using UnityEngine; public class kontrol : MonoBehaviour { public GameObject popupGameOver; // assign di Inspector public GameObject parent; int urutan = 0; bool sedangPindah = false; void Start() { AktifkanPuzzle(urutan); } void Update() { if (urutan >= parent.transform.childCount || sedangPindah) return; Transform currentPuzzle = parent.transform.GetChild(urutan); if (currentPuzzle.gameObject.activeSelf) { feedback f = currentPuzzle.GetComponent(); if (f != null && f.selesai) { sedangPindah = true; StartCoroutine(PindahPuzzleSetelahDelay(1.5f)); // delay agar senyum tampil } } } IEnumerator PindahPuzzleSetelahDelay(float delay) { yield return new WaitForSeconds(delay); // Nonaktifkan puzzle sekarang parent.transform.GetChild(urutan).gameObject.SetActive(false); // Naikkan urutan urutan++; // Cek apakah masih ada puzzle if (urutan < parent.transform.childCount) { AktifkanPuzzle(urutan); } else { Debug.Log("Semua puzzle selesai!"); popupGameOver.SetActive(true); // TAMPILKAN GAME OVER } sedangPindah = false; } void AktifkanPuzzle(int index) { for (int i = 0; i < parent.transform.childCount; i++) { parent.transform.GetChild(i).gameObject.SetActive(false); } parent.transform.GetChild(index).gameObject.SetActive(true); Debug.Log("Puzzle ke-" + (index + 1) + " aktif"); } public void UlangPermainan() { urutan = 0; for (int i = 0; i < parent.transform.childCount; i++) { GameObject puzzle = parent.transform.GetChild(i).gameObject; // Reset tiap potongan puzzle for (int j = 0; j < puzzle.transform.childCount; j++) { drag_puzzle dp = puzzle.transform.GetChild(j).GetComponent(); if (dp != null) { puzzle.transform.GetChild(j).position = dp.pos_awal; puzzle.transform.GetChild(j).localScale = dp.scale_awal; dp.on_pos = false; dp.on_tempel = false; } } // Reset feedback feedback f = puzzle.GetComponent(); if (f != null) { f.selesai = false; if (f.senyum != null) f.senyum.SetActive(false); } // Nonaktifkan semua dulu puzzle.SetActive(false); } // Aktifkan puzzle pertama parent.transform.GetChild(urutan).gameObject.SetActive(true); // Sembunyikan popup game over popupGameOver.SetActive(false); Debug.Log("Permainan diulang ke puzzle pertama."); } }