-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameController.cs
99 lines (77 loc) · 1.99 KB
/
GameController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;
using UnityEditor;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour
{
public int totalScore;
public int totalFood;
public int currentLevelIndex;
public static GameController instance;
public TextMeshProUGUI scoreText;
public TextMeshProUGUI totalText;
public GameObject applesObject;
public GameObject gameOver;
public GameObject nextLevel;
public GameObject alert;
public GameObject isChecked;
void Start()
{
int numberOfPrefabs = applesObject.transform.childCount;
//var prefebs = AssetDatabase.FindAssets("t:prefab", new string[] { "Assets/Prefabs" });
totalFood = numberOfPrefabs;
totalText.text = totalFood.ToString();
instance = this;
}
private void Update()
{
if (totalFood == totalScore)
{
isChecked.SetActive(true);
scoreText.color = Color.red;
}
}
public void UpdateScoreText()
{
scoreText.text = totalScore.ToString();
}
public void ShowGameOver()
{
gameOver.SetActive(true);
}
public void ShowNextLevel()
{
if (totalScore == totalFood)
{
nextLevel.SetActive(true);
}
else
{
alert.SetActive(true);
}
}
public void RestartGame(string lvlName)
{
SceneManager.LoadScene(lvlName);
}
//public void RestartGame()
//{
// SceneManager.LoadScene(SceneManager.GetActiveScene().name);
//}
public void LoadNextLevel()
{
currentLevelIndex++;
string nextLevelName = "lvl_" + currentLevelIndex;
if (SceneManager.GetSceneByName(nextLevelName) != null)
{
SceneManager.LoadScene(nextLevelName);
}
else
{
Debug.LogWarning("Next level not found: " + nextLevelName);
}
}
}