Question by
QuebecDev · Mar 16, 2021 at 10:53 PM ·
infinitewhile-loopexplain
Stuck in While Loop ** Cant find why!
I am stuck in a while loop, can someone tell me how this below is infinite?
Debug.Log(StartAt) = 10.15
Debug.Log(ReloadTime) = 2
My logic is...
+/-600frame (Because my FPS is around 600) the float Progress will equal 1
So in approx. 1201frame the float Progress will equal 2.1.
Then Progress = 2.1 will be greater then ReloadTime 2
private void OnReload(float Reload) { Reloading.SetActive(true); float ReloadTime = Reload; float StartAt = Time.time; float Progress = 0; double Fill = 0; double FPS = 0; while (bIsReload == true) { FPS = 1.0 / Time.deltaTime; Progress = (Time.time) - StartAt; Fill = (1 / (ReloadTime * FPS) * (Progress * FPS)); Reloading.GetComponent<Image>().fillAmount = (float)Fill; if (Progress > ReloadTime) { bIsReload = false; Reloading.SetActive(false); } } }
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613030817im_/https://answers.unity.com/themes/thub/images/avi.jpg)