Hello, my timer changes its value when counting down
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class loadingBar : MonoBehaviour
{
public bool playerCollecting;
[SerializeField]
private PickUpSystem pickup;
[SerializeField]
private GameObject loadingAnim;
[SerializeField]
private TMP_Text loadingtext;
//TIMER
[SerializeField]
private float countdownTime = 5f;
[SerializeField]
private float countdownSpeed = 1f;
private float remainingTime;
IEnumerator _timerCR;
//TIMER
// Start is called before the first frame update
void Start()
{
remainingTime = countdownTime;
UpdateTimerText();
ResetTimer();
}
// Update is called once per frame
void Update()
{
if (PickUpSystem.collecting == true)
{
StartCoroutine(LoadingBar());
}
{
if (PickUpSystem.collecting == false)
{
loadingAnim.SetActive(false);
StopAllCoroutines();
}
}
}
private void ResetTimer()
{
}
private void UpdateTimerText()
{
//loadingtext.text = timer.ToString();
}
IEnumerator LoadingBar(int timeRemaining = 5)
{
loadingAnim.SetActive(true);
for (int i = timeRemaining; i > 0; i--)
{
loadingtext.text = i.ToString("0");
yield return new WaitForSeconds(1);
UpdateTimerText();
}
CountdownFinished();
}
private void CountdownFinished()
{
}
}