-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildManager.cs
104 lines (88 loc) · 2.75 KB
/
BuildManager.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
100
101
102
103
104
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class BuildManager : MonoBehaviour
{
public List<ItemSlot> itemSlots;
public List<DragDrop> dragItems;
public Button buildButton;
public Button backButton;
public GameObject winPopupPanel;
public GameObject tryAgainPopupPanel;
public Button winPopupNextLevelButton;
public Button tryAgainPopupBackButton;
private void Start()
{
buildButton.onClick.AddListener(OnBuildButtonClick);
backButton.onClick.AddListener(OnBackButtonClick);
winPopupNextLevelButton.onClick.AddListener(OnNextLevelButtonClick);
tryAgainPopupBackButton.onClick.AddListener(OnBackButtonClick);
winPopupPanel.SetActive(false); // Ensure the win popup is initially hidden
tryAgainPopupPanel.SetActive(false); // Ensure the try again popup is initially hidden
}
private void OnBuildButtonClick()
{
bool allCorrect = true;
foreach (ItemSlot slot in itemSlots)
{
if (!slot.isCorrectItemPlaced)
{
allCorrect = false;
break;
}
}
if (allCorrect)
{
ShowWinPopup();
}
else
{
ShowTryAgainPopup();
}
}
private void OnBackButtonClick()
{
foreach (DragDrop item in dragItems)
{
item.ResetPosition();
}
foreach (ItemSlot slot in itemSlots)
{
slot.isCorrectItemPlaced = false;
}
winPopupPanel.SetActive(false); // Hide the win popup when resetting
tryAgainPopupPanel.SetActive(false); // Hide the try again popup when resetting
}
private void ShowWinPopup()
{
winPopupPanel.SetActive(true);
}
private void ShowTryAgainPopup()
{
tryAgainPopupPanel.SetActive(true);
}
private void OnNextLevelButtonClick()
{
string currentSceneName = SceneManager.GetActiveScene().name;
switch (currentSceneName)
{
case "Level1_DragDrop":
SceneManager.LoadScene("Level2_DragDrop");
break;
case "Level2_DragDrop":
SceneManager.LoadScene("Level3_DragDrop1");
break;
case "Level3_DragDrop1":
SceneManager.LoadScene("Level4_DragDrop1");
break;
case "Level4_DragDrop1":
// Handle what happens after Level 4 is completed, if needed
Debug.Log("Game Completed!");
break;
default:
Debug.LogError("Unexpected level name: " + currentSceneName);
break;
}
}
}