private void UpdateBehaviors() { Debug.Log("update behaviors"); float maxScore = 0; float currentScore = maxScore; int behaviorIndex = -1; for (int i = 0; i < behaviors.Length; i++) { currentScore = behaviors[i].GetScore(); if (currentScore > maxScore) { maxScore = currentScore; behaviorIndex = i; } } if (behaviorIndex >= 0) { currentBehavior = behaviors[behaviorIndex]; currentBehavior.Execute(); } }
private void Update() { timer += Time.deltaTime; if (timer >= updateRate) { timer = 0; if (currentBehavior != null) { currentBehavior.OnBehaviorUpdate(); if (currentBehavior.IsFinished()) { currentBehavior.Reset(); currentBehavior = null; } else { return; } } UpdateBehaviors(); } }