From 75d9081a31c12e2e1fb5c6f94b66327e2395c5e5 Mon Sep 17 00:00:00 2001 From: Ny Bruker <robinhs@stud.ntnu.no> Date: Fri, 9 Dec 2022 17:44:25 +0100 Subject: [PATCH] `SetElements` now resets the list. - Also fixes exception from list being null. --- MrBigsock/Assets/Code/UI/AbilityCluster.cs | 37 +++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/MrBigsock/Assets/Code/UI/AbilityCluster.cs b/MrBigsock/Assets/Code/UI/AbilityCluster.cs index 44832dbb..659c3d05 100644 --- a/MrBigsock/Assets/Code/UI/AbilityCluster.cs +++ b/MrBigsock/Assets/Code/UI/AbilityCluster.cs @@ -6,29 +6,30 @@ using BigSock.Service; namespace BigSock.UI { - public class AbilityCluster : MonoBehaviour - { - private const string ABILITYELEMENT = "UI/Ability"; - private List<AbilityElement> abilityList; + public class AbilityCluster : MonoBehaviour + { + private const string ABILITYELEMENT = "UI/Ability"; + private List<AbilityElement> abilityList; - public void SetElements(int elementAmount) + public void SetElements(int elementAmount) { - for (int i = 0; i < elementAmount; ++i) + abilityList = new List<AbilityElement>(); + for (int i = 0; i < elementAmount; ++i) { - abilityList.Add(PrefabService.SINGLETON.Instance(ABILITYELEMENT, transform).GetComponent<AbilityElement>()); - } - } + abilityList.Add(PrefabService.SINGLETON.Instance(ABILITYELEMENT, transform).GetComponent<AbilityElement>()); + } + } - public void SetCooldown(int index, float amount) - { - abilityList[index].WithCooldown(amount); - } + public void SetCooldown(int index, float amount) + { + abilityList[index].WithCooldown(amount); + } - public void SetCharge(int index, float amount) - { - abilityList[index].WithCharge(amount); - } + public void SetCharge(int index, float amount) + { + abilityList[index].WithCharge(amount); + } - } + } } -- GitLab