222 lines
5.3 KiB
C#
222 lines
5.3 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class Data9
|
|
{
|
|
public static int DataLevel, DataScore, DataWaktu, DataNyawa;
|
|
}
|
|
|
|
public class gamesistem9 : MonoBehaviour
|
|
{
|
|
public static gamesistem9 instance;
|
|
|
|
//public static bool NewGame = true; //ketika new game akan ngulang data, ketika enggak, akan melanjutkan dengan data yang ada
|
|
int MaxLevel = 10;
|
|
|
|
|
|
[Header("DataPermainan")]
|
|
public bool GameAktif;
|
|
public bool GameSelesai;
|
|
public bool GameFinish; //perubahan
|
|
public int Target, DataSaatIni;
|
|
//public int DataScore, DataWaktu, DataNyawa;
|
|
|
|
[Header("Komponen UI")]
|
|
public TMP_Text Teks_Level;
|
|
public TMP_Text Teks_Score;
|
|
public TMP_Text Teks_Waktu;
|
|
public RectTransform Ui_Darah;
|
|
|
|
[Header("Obj GUI")]
|
|
public GameObject Gui_Pause;
|
|
public GameObject Gui_Transisi;
|
|
|
|
|
|
[Space]
|
|
public bool SistemAcak;
|
|
|
|
[System.Serializable]
|
|
public class DataGame
|
|
{
|
|
public string Nama;
|
|
public Sprite Gambar;
|
|
|
|
}
|
|
|
|
[Header("Settingan Standar")]
|
|
|
|
public DataGame[] DataPermainan;
|
|
|
|
[Space]
|
|
|
|
public ObjTempatDrob[] Drop_Tempat;
|
|
public ObjDrag[] Drag_Obj;
|
|
|
|
//agar script lain dapat mengakses di game system
|
|
private void Awake() //saat pertama kali scene dibuka
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start() //objek disable/enable bida diakses lagi
|
|
{
|
|
//AcakSoal();
|
|
GameAktif = false;
|
|
GameSelesai = false;
|
|
GameFinish = false; //tambahan
|
|
SetSoal();
|
|
ResetData();
|
|
Target = 1;
|
|
GameAktif = true;
|
|
}
|
|
|
|
void ResetData()
|
|
{
|
|
if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "game80")
|
|
{
|
|
//NewGame = false;
|
|
Data9.DataLevel = 0;
|
|
Data9.DataWaktu = 60 * 5;
|
|
Data9.DataScore = 0;
|
|
Data9.DataNyawa = 5;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
float s;
|
|
void Update()
|
|
{
|
|
//if (Input.GetKeyDown(KeyCode.Space))
|
|
// AcakSoal();
|
|
|
|
if (GameAktif && !GameSelesai)
|
|
{
|
|
if (Data9.DataWaktu > 0)
|
|
{
|
|
s += Time.deltaTime;
|
|
if (s >= 1)
|
|
{
|
|
Data9.DataWaktu--;
|
|
s = 0;
|
|
}
|
|
}
|
|
|
|
if (Data9.DataWaktu <= 0)
|
|
{
|
|
GameAktif = false;
|
|
GameSelesai = true;
|
|
GameFinish = false; //tambahan
|
|
|
|
//game kalah
|
|
KumpulanSuara.instance.Panggil_Sfx(5);
|
|
|
|
Gui_Transisi.GetComponent<UiControl>().Btn_Pindah("gameselesai9");
|
|
}
|
|
|
|
if (Data9.DataNyawa <= 0)
|
|
{
|
|
GameSelesai = true;
|
|
GameAktif = false;
|
|
GameFinish = false; //tambahan
|
|
|
|
//fungsi kalah
|
|
KumpulanSuara.instance.Panggil_Sfx(5);
|
|
|
|
Gui_Transisi.GetComponent<UiControl>().Btn_Pindah("gameselesai9");
|
|
}
|
|
|
|
if (DataSaatIni >= Target)
|
|
{
|
|
GameFinish = true; //tambahan
|
|
//GameSelesai = true;
|
|
GameSelesai = false; //perubahan
|
|
GameAktif = false;
|
|
|
|
//kita menang
|
|
|
|
if (Data9.DataLevel < (MaxLevel - 1))
|
|
{
|
|
Data9.DataLevel++;
|
|
//pindah ke next level\
|
|
|
|
//tanpa transisi
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("game" + (80 + Data9.DataLevel));
|
|
|
|
//Gui_Transisi.GetComponent<UiControl>().Btn_Pindah("game" + Data.DataLevel);
|
|
|
|
KumpulanSuara.instance.Panggil_Sfx(3);
|
|
}
|
|
else
|
|
{
|
|
//game selesai pindah ke menu selesai
|
|
//Gui_Transisi.GetComponent<UiControl>().Btn_Pindah("gameselesai");
|
|
Gui_Transisi.GetComponent<UiControl>().Btn_Pindah("gamefinish9"); //perubahan
|
|
KumpulanSuara.instance.Panggil_Sfx(4);
|
|
KumpulanSuara.instance.Panggil_Sfx(6);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
SetInfoUI();
|
|
}
|
|
|
|
|
|
|
|
public void SetSoal()
|
|
{
|
|
for (int i = 0; i < Drag_Obj.Length; i++)
|
|
{
|
|
Drag_Obj[i].ID = i; // ID sesuai urutan data
|
|
Drag_Obj[i].Teks.text = DataPermainan[i].Nama;
|
|
}
|
|
|
|
for (int i = 0; i < Drop_Tempat.Length; i++)
|
|
{
|
|
Drop_Tempat[i].Drob.ID = i; // ID sesuai urutan data
|
|
Drop_Tempat[i].Gambar.sprite = DataPermainan[i].Gambar;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetInfoUI()
|
|
{
|
|
Teks_Level.text = (Data9.DataLevel + 1).ToString();
|
|
Teks_Score.text = Data9.DataScore.ToString();
|
|
|
|
int Menit = Mathf.FloorToInt(Data9.DataWaktu / 60); //01
|
|
int Detik = Mathf.FloorToInt(Data9.DataWaktu % 60); //30
|
|
Teks_Waktu.text = Menit.ToString("00") + ":" + Detik.ToString("00");
|
|
|
|
Ui_Darah.sizeDelta = new Vector2(63f * Data9.DataNyawa, 63f);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//btn pause
|
|
public void Btn_Pause(bool pause)
|
|
{
|
|
if (pause)
|
|
{
|
|
GameAktif = false;
|
|
Gui_Pause.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
GameAktif = true;
|
|
Gui_Pause.SetActive(false);
|
|
}
|
|
}
|
|
}
|