So i had countdown timer bar prefab which instantiated in vertical layout group. It’s work perfectly fine for the 1st time, the timer will reducing as it should be. But when i instantiate more, the old one will resetting it’s value back to beginning.
public class CountDownTimerBar : MonoBehaviour
{
float maxTime;
public static float runningTime;
Image timerBar;
void Awake()
{
maxTime = PlayerPrefs.GetFloat("SetPartyEsc");
runningTime = maxTime;
timerBar = GetComponent<Image>();
}
void Update()
{
if (runningTime > 0)
{
runningTime -= Time.deltaTime;
timerBar.fillAmount = runningTime / maxTime;
}
}
}
This is my instantiate script :
public GameObject cardPrefab;
public GameObject menu;
public float addHeigthValue = 190f;
private VerticalLayoutGroup layout;
private RectTransform rt;
void Start()
{
layout = GetComponent<VerticalLayoutGroup>();
rt = GetComponent<RectTransform>();
}
public void AddaCard()
{
if(rt.transform.childCount < 4)
{
Instantiate(cardPrefab, layout.transform);
CloseMenu();
}
else if(rt.transform.childCount >= 4)
{
Instantiate(cardPrefab, layout.transform);
rt.sizeDelta = new Vector2(rt.sizeDelta.x, (rt.sizeDelta.y + addHeigthValue));
CloseMenu();
}
}
public void CloseMenu()
{
menu.gameObject.SetActive(false);
}
Here’s some images…
It’s working for 1st instantiate :
But when i instantiate another one…
Can anyone help me with this ?