Unlockable Levels and Added empty 7 levels
This commit is contained in:
@@ -7,10 +7,15 @@ namespace UI
|
||||
public class LevelButton : MonoBehaviour
|
||||
{
|
||||
private TMP_Text text = null;
|
||||
public int LevelNumber { get; private set; } = 0;
|
||||
|
||||
private void Awake() => text = GetComponentInChildren<TMP_Text>();
|
||||
|
||||
public void SetLevel(string levelName) => text.text = levelName;
|
||||
public void StartLevel() => LevelManager.Instance.SwitchToLevel(text.text);
|
||||
public void SetLevel(string levelName)
|
||||
{
|
||||
text.text = levelName;
|
||||
LevelNumber = System.Int32.Parse(levelName);
|
||||
}
|
||||
public void StartLevel() => LevelManager.Instance.SwitchToLevel(LevelNumber);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Level;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
@@ -8,13 +10,15 @@ namespace UI
|
||||
{
|
||||
[SerializeField] private Vector2Int maxGridSize = Vector2Int.one;
|
||||
private GameObject levelButtonPrefab = null;
|
||||
private List<GameObject> instances = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
levelButtonPrefab = Resources.Load<GameObject>("UI/Level Button Variant");
|
||||
instances = new List<GameObject>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
private void OnEnable()
|
||||
{
|
||||
LevelButton instance = null;
|
||||
|
||||
@@ -48,8 +52,17 @@ namespace UI
|
||||
instancePosition.x = columnOffset + columnIndex * instanceRectTransform.rect.width * 1.5f;
|
||||
instanceRectTransform.localPosition = instancePosition;
|
||||
|
||||
instance.GetComponent<Button>().interactable = LevelManager.Instance.IsLevelUnlocked(instance.LevelNumber);
|
||||
|
||||
instances.Add(instance.gameObject);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
foreach (GameObject gameObject in instances)
|
||||
Destroy(gameObject.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user