IEnumerator WaitTrafficLight() { currentStopTime = 0f; yield return(FixedUpdateManager.WaitUntilFixed(() => distanceToStopTarget <= stopLineDistance)); if (prevMapLane.stopLine.currentState == MapData.SignalLightStateType.Green) { yield break; // light is green so just go } isStopLight = true; yield return(FixedUpdateManager.WaitUntilFixed(() => atStopTarget)); // wait if until reaching stop line if ((isRightTurn && prevMapLane.rightLaneReverse == null)) { var waitTime = RandomGenerator.NextFloat(0f, 3f); var startTime = currentStopTime; yield return(FixedUpdateManager.WaitUntilFixed(() => prevMapLane.stopLine.currentState == MapData.SignalLightStateType.Green || currentStopTime - startTime >= waitTime)); isStopLight = false; yield break; } yield return(FixedUpdateManager.WaitUntilFixed(() => prevMapLane.stopLine.currentState == MapData.SignalLightStateType.Green)); // wait until green light if (isLeftTurn || isRightTurn) { yield return(FixedUpdateManager.WaitForFixedSeconds(RandomGenerator.NextFloat(1f, 2f))); // wait to creep out on turn } isStopLight = false; }
IEnumerator WaitStopSign() { yield return(FixedUpdateManager.WaitUntilFixed(() => distanceToStopTarget <= stopLineDistance)); isStopSign = true; currentStopTime = 0f; hasReachedStopSign = false; yield return(FixedUpdateManager.WaitUntilFixed(() => distanceToStopTarget < minTargetDistance)); prevMapLane.stopLine.intersection.EnterStopSignQueue(controller); hasReachedStopSign = true; yield return(FixedUpdateManager.WaitForFixedSeconds(stopSignWaitTime)); yield return(FixedUpdateManager.WaitUntilFixed(() => prevMapLane.stopLine.intersection.CheckStopSignQueue(controller))); hasReachedStopSign = false; isStopSign = false; }