Hello,
I’m using a trigger to start this function (dynamically) meaning that the trigger send it’s state to the function, i’m trying to exit that function before it reaches the second ELSE condition using return, but it always get to Else and execute it.
public void rlup(bool rltp) {
if (rltp) {
if (stcint [4] >= 60) {
startFx (1);
} else {
startFx (2);
toggle [0].isOn = false;
}
return;
} else {
gameText [1].text = stcint [4].ToString ();
startFx (0);
}
}
By the second else, do you mean the one under:
else {
gameText [1].text = stcint [4].ToString ();
startFx (0);
}
If so, that would be hit if rltp would be false. If rltp were true, it would never hit the clause, and the return is extraneous.
1 Like
Yes, i mean the one you mentioned, it is executed even if the toggle is true (why: because if i have a coins less than 60 i set that toggle to false in line number 7), i want to exit the function after i set the toggle to false (after line 7), i don’t want it to keep executing.
The problem was that the toggle execute the function every time it’s value change (not every click), so the function was get stopped by RETURN, but then the toggle switch execute the function again (because it was set to false in line number 7) and enter the second else condition. after one full day of searching, i found this thread which is full of different solutions to this problem.
forum.unity.com/threads/change-the-value-of-a-toggle-without-triggering-onvaluechanged.275056/