how to execute a code only once in update function in unity (cursed method)
sealed class CodeState {
public string stateName;
public CodeState(string stateName) {
this.stateName = stateName;
}
}
public static class VarsNStuff {
public static List<CodeState> states = new List<CodeState>() {new CodeState("Finished"),
new CodeState("Incomplete");
}
}
private class Test : MonoBehaviour {
private CodeState state = VarsNStuff.states[1];
public override void Update() {
if (this.state != VarsNStuff.states[0]{
//Do code.
foreach (dynamic state in VarsNStuff.states) {
if (this.state != state) {
this.state = state;
break;
} }
}
}
}