We Win
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class WinSceneController : MonoBehaviour
|
||||
{
|
||||
private UIDocument uiDocument;
|
||||
private Button button;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
private void OnEnable()
|
||||
{
|
||||
uiDocument ??= GetComponent<UIDocument>();
|
||||
if (uiDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var root = uiDocument.rootVisualElement;
|
||||
if (root == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
button = root.Q<Button>("Button");
|
||||
|
||||
button.clicked += () => HandleStartClicked("MainMenu");
|
||||
}
|
||||
|
||||
private void HandleStartClicked(string sceneName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(sceneName))
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c6f6aec456035b4585c695c990ec825
|
||||
@@ -1,18 +1,20 @@
|
||||
using Unity.VectorGraphics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class WinScreenController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int winScore = 100;
|
||||
|
||||
private VisualElement winScreen; // ✅ DECLARED HERE
|
||||
private string winScreenScene = "Win"; // ✅ DECLARED HERE
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
var root = GetComponent<UIDocument>().rootVisualElement;
|
||||
/*var root = GetComponent<UIDocument>().rootVisualElement;
|
||||
winScreen = root.Q<VisualElement>("WinScreen");
|
||||
|
||||
winScreen.style.display = DisplayStyle.None;
|
||||
winScreen.style.display = DisplayStyle.None;*/
|
||||
|
||||
ScoreManager.OnScoreChanged += CheckWinCondition;
|
||||
}
|
||||
@@ -26,8 +28,7 @@ public class WinScreenController : MonoBehaviour
|
||||
{
|
||||
if (score >= winScore)
|
||||
{
|
||||
winScreen.style.display = DisplayStyle.Flex;
|
||||
Time.timeScale = 0f;
|
||||
SceneManager.LoadScene(winScreenScene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user