Hello. I want to go through a function and if a condition is met, call another function. After it does it’s actions, the second function will always call the first function. Unity says I cannot do this because it creates a loop…but it’s not technicaly a loop, right (it will stop when the condition is not met)? How can I do this:
function MyFunction1(){
do some stuff
yield;
if(condition==true)
MyFunction2()
}
function MyFunction2()
do some more stuff
yield;
MyFunction1();
}
as @Fattie says and unity, you are technically looping your function, even if there is a condition, if it loops more then once, then it’s a looping function. But fear not you do not need a yield, you could use a simple unity function InvokeRepeating, very handy. Then inside of the function your repeating thats invoked have your condition and if the condition is met or isnt depending how you want it you can cancel the invoke by CancelInvoke.
function Start () {
InvokeRepeating(“example”, 1.0, 1.0);
}
function example () {
if(condition1 == conditionvalue)
CancelInvoke(“example”);
}