I can’t figure out why my UI Stamina Container turns into a white block once I click the dash input (spacebar) in any other scene than the one I set it up in. The dash still works (refills/dash) but the image is blocked out. Any ideas?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Stamina : Singleton<Stamina>
{
public int CurrentStamina { get; private set; }
[SerializeField] private Sprite fullStaminaImage, emptyStaminaImage;
[SerializeField] private int timeBetweenStaminaRefresh = 3;
private Transform staminaContainer;
private int startingStamina = 3;
private int maxStamina;
const string STAMINA_CONTAINER_TEXT = "Stamina Container";
protected override void Awake()
{
base.Awake();
maxStamina = startingStamina;
CurrentStamina = startingStamina;
}
private void Start()
{
staminaContainer = GameObject.Find(STAMINA_CONTAINER_TEXT).transform;
}
public void UseStamina()
{
CurrentStamina--;
UpdateStaminaImages();
StopAllCoroutines();
StartCoroutine(RefreshStaminaRoutine());
}
public void RefreshStamina()
{
if (CurrentStamina < maxStamina && !PlayerHealth.Instance.IsDead)
{
CurrentStamina++;
}
UpdateStaminaImages();
}
public void ReplenishStaminaOnDeath()
{
CurrentStamina = startingStamina;
UpdateStaminaImages();
}
private IEnumerator RefreshStaminaRoutine()
{
while (true)
{
yield return new WaitForSeconds(timeBetweenStaminaRefresh);
RefreshStamina();
}
}
private void UpdateStaminaImages()
{
for (int i = 0; i < maxStamina; i++)
{
Transform child = staminaContainer.GetChild(i);
Image image = child?.GetComponent<Image>();
if (i <= CurrentStamina - 1)
{
image.sprite = fullStaminaImage;
}
else
{
image.sprite = emptyStaminaImage;
}
}
}
}