on / off if statement C#

Hi again,

Oh my gosh I’m learning so much! Thank you all for helping :slight_smile:

I’m having difficulty working out how to do the following in C#:

Ive got this script running once per second via a yield. Being that there is the potential for it to run hundreds of times, how can i check if it’s been run once so that it doesn’t keep repeating? I don’t want to stop the yield as such but only ‘shut off’ an if statement and i want to add more if statements so I’m guessing i need some sort of variable thats local to the if statement somehow?

I tried using a bool but obviously it just keeps changing the variable back to false and continues to run.

    bool togglething = false;
    if(convertToSeconds <= 20788 && convertToSeconds >= 18788 && togglething ==false){
       togglething = true;
        print("I'm in");
       
    }

Thanks you awesome dudes! I will have your babies if you can work this out :stuck_out_tongue:

Declare the bool at the class scope

bool togglething = false;

void MyMethod(){
     if(convertToSeconds <= 20788 && convertToSeconds >= 18788 && togglething ==false){
         togglething = true;
         print("I'm in");
     }
}

Note that I already have enough babies, but I do appreciate the offer.