61 lines
2.3 KiB
C#
61 lines
2.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public enum Difficulty { Easy, Medium, Hard }
|
|
|
|
public class DifficultyMenu : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button _easyButton;
|
|
[SerializeField] private Button _mediumButton;
|
|
[SerializeField] private Button _hardButton;
|
|
[SerializeField] private Button _startButton;
|
|
[SerializeField] private GameObject _setingBar; // Ссылка на весь панель меню
|
|
[SerializeField] private CardsSpawner _spawner; // Ссылка на CardsSpawner в инспекторе
|
|
|
|
private Difficulty _selectedDifficulty = Difficulty.Medium; // По умолчанию
|
|
|
|
private void Start()
|
|
{
|
|
_easyButton.onClick.AddListener(() => SetDifficulty(Difficulty.Easy));
|
|
_mediumButton.onClick.AddListener(() => SetDifficulty(Difficulty.Medium));
|
|
_hardButton.onClick.AddListener(() => SetDifficulty(Difficulty.Hard));
|
|
_startButton.onClick.AddListener(StartGame);
|
|
}
|
|
|
|
private void SetDifficulty(Difficulty diff)
|
|
{
|
|
_selectedDifficulty = diff;
|
|
// Опционально: подсвети кнопку или покажи текст
|
|
Debug.Log($"Выбрана сложность: {diff}");
|
|
}
|
|
|
|
private void StartGame()
|
|
{
|
|
_setingBar.SetActive(false); // Скрываем меню
|
|
StartCoroutine(StartGameDelayed());
|
|
|
|
|
|
}
|
|
private System.Collections.IEnumerator StartGameDelayed()
|
|
{
|
|
// Ждем один кадр. Это гарантирует, что главный поток свободен
|
|
// от процессов загрузки и инициализации UI/TextCore.
|
|
yield return null;
|
|
int rows = 2, columns = 4; // Default easy
|
|
switch (_selectedDifficulty)
|
|
{
|
|
case Difficulty.Easy:
|
|
rows = 2; columns = 4; // 8 карт, 4 пары
|
|
break;
|
|
case Difficulty.Medium:
|
|
rows = 2; columns = 5; // 10 карт, 5 пар
|
|
break;
|
|
case Difficulty.Hard:
|
|
rows = 3; columns = 4; // 12 карт, 6 пар
|
|
break;
|
|
}
|
|
// Здесь ваш код, который раньше был в конце StartGame():
|
|
_spawner.Spawn();
|
|
}
|
|
}
|