Fix initialization bug

This commit is contained in:
Michal Pikulski
2025-11-19 23:57:32 +01:00
parent e76fb0a62e
commit 43fc6c327a

View File

@@ -1,5 +1,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Core.Lifecycle;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@@ -9,7 +10,7 @@ namespace Minigames.CardSorting.UI
/// Displays and animates lives for the card sorting minigame. /// Displays and animates lives for the card sorting minigame.
/// Manages a layout group of life icons with add/remove animations. /// Manages a layout group of life icons with add/remove animations.
/// </summary> /// </summary>
public class LivesDisplay : MonoBehaviour public class LivesDisplay : ManagedBehaviour
{ {
[Header("Configuration")] [Header("Configuration")]
[SerializeField] private LayoutGroup layoutGroup; [SerializeField] private LayoutGroup layoutGroup;
@@ -21,7 +22,11 @@ namespace Minigames.CardSorting.UI
private GameObject lifeIconPrefab; private GameObject lifeIconPrefab;
private List<GameObject> lifeIcons = new List<GameObject>(); private List<GameObject> lifeIcons = new List<GameObject>();
private void Awake() /// <summary>
/// Initialize the display with the maximum number of lives.
/// Clones the prefab element multiple times.
/// </summary>
public void Initialize(int maxLives)
{ {
if (layoutGroup == null) if (layoutGroup == null)
{ {
@@ -33,14 +38,7 @@ namespace Minigames.CardSorting.UI
{ {
lifeIconPrefab = layoutGroup.transform.GetChild(0).gameObject; lifeIconPrefab = layoutGroup.transform.GetChild(0).gameObject;
} }
}
/// <summary>
/// Initialize the display with the maximum number of lives.
/// Clones the prefab element multiple times.
/// </summary>
public void Initialize(int maxLives)
{
// Clear existing lives // Clear existing lives
ClearAllLives(); ClearAllLives();