How to call or invoke an if statement multiple times, while and do while doesn't work

alessio barbagini 1 Reputation point
2021-06-07T10:17:20.927+00:00

Hello everybody, I am a 3 month old newby in the C# world. I am following courses and tutorials, i got stuck in this.

I am doing a little program that i want to transfer to unity , about breath cycles.
Inhale, hold, exhale.
I got the if statements to start one when the precedent finishes, but it does it just one time, i.e. inhale, keep, exhale, instead of repeating it till the current time is equal to the total time.

i tried with do, while, other ifs , but it does not work. Thank you in advance for any tips or advises.
Alessio

  public float inhale = 2;
    public float keepIn = 8;
    public float exhale = 4;

    public float currentTime = 0;
    public float practiceTime = 50;

    bool timerIsRunning = false;
    bool timerIsRunning2 = false;
    bool timerIsRunning3 = false;

    Action action;

    void Start()
    {

        textComponent.text = "INHALE";
        timerIsRunning = true;
        timerIsRunning2 = false;
        timerIsRunning3 = false;

    }

    // Update is called once per frame
    void Update()
    {
        if (practiceTime > currentTime)
        {


            practiceTime -= Time.deltaTime;
            ManageActions();

        }


    }

    private void ManageActions()
    {
      // if (currentTime < practiceTime)
       // {

            //  do
            // {

            timerIsRunning = true;
                if (timerIsRunning)
                {
                    // inhale
                    if (inhale > 0)
                    {

                        inhale -= Time.deltaTime;
                    }
                    else
                    {

                        inhale = 0;
                        timerIsRunning = false;

                    }
                }
                // keep in
                if (timerIsRunning == false)
                {
                    timerIsRunning2 = true;

                    if (timerIsRunning2)
                    {
                        if (keepIn > 0)
                        {

                            textComponent.text = "KEEP IN ";

                            keepIn -= Time.deltaTime;
                        }
                        else
                        {

                            keepIn = 0;
                            timerIsRunning2 = false;
                        }
                    }


                    if (timerIsRunning2 == false)
                    {
                        // exhale
                        timerIsRunning3 = true;

                        if (timerIsRunning3)
                        {

                            textComponent.text = "EXHALE";
                            if (exhale > 0)
                            {


                                exhale -= Time.deltaTime;
                            }
                            else
                            {

                                exhale = 0;
                                timerIsRunning3 = false;                       
                            }
                }
           }
        }
Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
282 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. WhTurner 1,611 Reputation points
    2021-06-07T11:46:59.44+00:00

    In Small Basic you can use While ... .... and EndWhille

    For C# you have to ask in a C# forum.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.