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);
            }
        }
    }

I’m facin’ this problem too. And my code is it:

    public string DeleteLastZero(string example)
    {
        if (!float.TryParse(example, out float number)) return example;
        if ((example.Contains('.') || example.Contains(',')))
        {
            do
            {
                if (example[example.Length - 1] == '0')
                {
                    example.Remove(example.Length - 1);
                }
            } while (example[example.Length - 1] == '0');

        }
        return example;
    }

İf any string value have a number whic is have “,” and “.”, and its contin too much meanless zero to end of it, this void cleans that zero chars.But when this code is triggered, Unity goes down.