Resolving error
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class MainMenuController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string startSceneName = "Level1";
|
||||
private UIDocument uiDocument;
|
||||
private Button startButton;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
uiDocument ??= GetComponent<UIDocument>();
|
||||
if (uiDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var root = uiDocument.rootVisualElement;
|
||||
if (root == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
startButton = root.Q<Button>("Start");
|
||||
if (startButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
startButton.clicked += HandleStartClicked;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (startButton != null)
|
||||
{
|
||||
startButton.clicked -= HandleStartClicked;
|
||||
startButton = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleStartClicked()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(startSceneName))
|
||||
{
|
||||
SceneManager.LoadScene(startSceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user