How to perform the action one time when condition carrying?

))) I worked on many game engines and in every has been two functions Update and Loop (or For Each).

Update doing code only one time when condition carrying (set value or something).
Loop function doing code every frame for object when condition carrying.
So, how simple play a sound one time or set and get value when condition carrying?

Example on LispCode:

(update)
if (engineRPM > 8000) {
if (currentgear = 2) {
play (gearshift.wav; 1000; 0); //one time playing
set variable (currentgear): 3;
set variable (pitch): 10;
set variable (moment): 4;
wait: 0,2;
set variable (input): 1; //this is part of code, so this action need a call after wait time
}
}
/

(loop)
set variable (engineRPM): wheelRL.torque + wheelRR.torque / moment;
play (engine.wav; 1000; engineRPM / pitch); // loop playing with 1000 volume and pitch from updated variable
/

How such very simple action write in Unity? (on js, I do not like c#)
I write all in Update function and all called everyframe((( how use for example “wait”?

With coroutines you can have wait,

So you could make your own update coroutine loop (that keeps looping always with while(true){…})

note, you need to add 1 frame delay in the loop, so that it wont hang,

yield; // wait for one frame

see old docs for js Unity Script Reference – Overview: Coroutines & Yield

Unity uses UnityScript which is not really JS and it is being phased out. Very few people use UnityScript and therefore it is difficult to find help specifically for it. Just a side note.

thanks for answers. I guessed about coroutine and bool when read unity API.

On js I created games in macromedia flash more in 2005))) and I very do like this language how and HTML) very simple represent needed actions. But js as I understand in Unity It does not use the full language or something like that. Ok, UnityScript quite complicated for me, beacause I accustomed to simpler solutions. But perhaps it is simpler than it seems

Now my problem in GearBox and GearRatio for car, it work but not quite how needed. Not smoothly and without gear ratio curve.