121 lines
3.8 KiB
C#
121 lines
3.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class FinishPick : MonoBehaviour
|
|
{
|
|
[Header("Panel Skor")]
|
|
public GameObject panelLevelComplete;
|
|
public TextMeshProUGUI scoreText;
|
|
public TextMeshProUGUI highScoreText;
|
|
public GameObject mazeParent;
|
|
|
|
[Header("Panel Total score")]
|
|
public GameObject totalScorePanel;
|
|
//public TextMeshProUGUI scoreText;
|
|
public TextMeshProUGUI totalScoreText;
|
|
|
|
AudioGame audioGame;
|
|
|
|
private void Awake()
|
|
{
|
|
audioGame = GameObject.FindGameObjectWithTag("Audio").GetComponent<AudioGame>();
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (collision.CompareTag("Finish"))
|
|
{
|
|
GameObject[] remainingItems = GameObject.FindGameObjectsWithTag("PickItem");
|
|
|
|
if (remainingItems.Length == 0)
|
|
{
|
|
// Sembunyikan maze di belakang UI
|
|
if (mazeParent != null)
|
|
{
|
|
SpriteRenderer[] mazeRenderers = mazeParent.GetComponentsInChildren<SpriteRenderer>();
|
|
foreach (SpriteRenderer sr in mazeRenderers)
|
|
{
|
|
sr.sortingOrder = -10;
|
|
}
|
|
}
|
|
|
|
// Tampilkan panel skor
|
|
if (panelLevelComplete != null)
|
|
{
|
|
panelLevelComplete.SetActive(true);
|
|
audioGame.PlaySFX(audioGame.popUp);
|
|
}
|
|
|
|
// Update teks skor
|
|
if (scoreText != null && highScoreText != null)
|
|
{
|
|
GameSession.Instance.MarkLevelComplete();
|
|
GameSession.Instance.SaveLevelScore();
|
|
|
|
string currentLevelName = SceneManager.GetActiveScene().name;
|
|
int highScore = GameSession.Instance.GetHighScore(currentLevelName);
|
|
|
|
scoreText.text = "Skor kamu: " + GameSession.Instance.CurrentScore;
|
|
highScoreText.text = "High Score: " + highScore.ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Masih ada soal yang belum dijawab!");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void LoadNextLevelFromCurrent()
|
|
{
|
|
string currentScene = SceneManager.GetActiveScene().name;
|
|
string nextScene = LevelControl.Instance.NextLevel(currentScene);
|
|
//int totalScore = GameSession.Instance.GetTotalScore();
|
|
string currentMateri = GameSession.Instance.GetMateriFromLevelName(currentScene);
|
|
|
|
bool isLastLevelInMateri = LevelControl.Instance.IsLastLevelOfMateri(currentScene);
|
|
|
|
if (!string.IsNullOrEmpty(nextScene))
|
|
{
|
|
LevelControl.Instance.UnlockedNewLevel();
|
|
SceneManager.LoadScene(nextScene);
|
|
}
|
|
else
|
|
{
|
|
panelLevelComplete.SetActive(false);
|
|
//totalScorePanel.SetActive(true);
|
|
|
|
if (isLastLevelInMateri)
|
|
{
|
|
totalScorePanel.SetActive(true);
|
|
|
|
GameSession.Instance.SaveLevelScore();
|
|
|
|
int totalAllScore = GameSession.Instance.GetTotalScoreByMateri(currentMateri);
|
|
|
|
if (totalScoreText != null)
|
|
totalScoreText.text = "Total skor kamu: " + totalAllScore.ToString();
|
|
|
|
Debug.Log("Level terakhir dari materi: " + currentMateri);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Sudah di level terakhir, tapi bukan akhir dari suatu materi.");
|
|
}
|
|
// Tambahkan logika kembali ke menu atau end screen jika perlu
|
|
}
|
|
}
|
|
|
|
//private void OnTriggerExit2D(Collider2D collision)
|
|
//{
|
|
//if (collision.tag == "Finish")
|
|
//{
|
|
//LevelControl.Instance.NextLevel();
|
|
//buttonNext.SetActive(false);
|
|
//}
|
|
//}
|
|
}
|