📜  如何在统一的更新函数中只执行一次代码(被诅咒的方法) - C#代码示例

📅  最后修改于: 2022-03-11 14:48:41.329000             🧑  作者: Mango

代码示例1
sealed class CodeState {
    public string stateName;
    public CodeState(string stateName) {
        this.stateName = stateName;
    }
}
public static class VarsNStuff {
    public static List states = new List() {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;
                } }
        }
    }
}