IEnumerator Move() { Vector3 point = RandomPointOnNavMesh(); float waitTime = 3f; float elapsedTime = 0f; // Move to a random location while (currentState == State.Move) { if (!health.isAlive()) { StopAllCoroutines(); yield return(null); } actions.Move(point); elapsedTime += Time.deltaTime; // Select a new destination if (elapsedTime >= waitTime) { elapsedTime = 0f; point = RandomPointOnNavMesh(); } // If can fire, then fire if (Time.time >= nextFire) { ChangeState(State.Attack); yield break; } yield return(null); } }
private void Update() { if (dead) { return; } if (gameObject.CompareTag("Preview")) { return; } UnitActions.Move(this); UpdateMovingAnimation(); UnitActions.UpdateIsSwimming(this); updateCounter = (updateCounter + 1) % GameManager.gameManager.countsBetweenUpdates; if (updateCounter == 0) { UnitActions.SetThought(this); //UnitActions.WanderIfDeadTarget(this); UnitActions.HungerEffect(this); UnitActions.ThirstEffect(this); UnitActions.TurnHungryChance(this); UnitActions.TurnThirstyChance(this); UnitActions.TurnHornyChance(this); UnitActions.HealthRegenEffect(this); unitState = UnitStateMachine.NextState(this); } }