/// <summary> /// Checks whether a car is on a stop point /// </summary> /// <param name="policePath"></param> private void CheckStopPoint(PolicePath policePath) { if (Vector3.Distance(transform.position, policePath.StopPoint) <= StopInfelicity) { speedAdjustment = SpeedAdjustmentEnum.Stop; policePathMoving = PolicePathMovingEnum.Stop; //Debug.Log(gameObject.name + ": стою у полицейского"); StartCoroutine(StoppingCoroutine()); StopCoroutine(StoppingCoroutine()); } }
/// <summary> /// Counts 3 seconds at a stop point after which the car can begin to move /// </summary> /// <returns></returns> private IEnumerator StoppingCoroutine() { //Debug.Log(gameObject.name + "=> Заход в коррутину!"); while (policePathMoving != PolicePathMovingEnum.Stop) { yield return(null); } yield return(new WaitForSeconds(3)); policePathMoving = PolicePathMovingEnum.Starting; speedAdjustment = SpeedAdjustmentEnum.Increase; Stopped = true; }
/// <summary> /// Changes police path statements (PolicePathMovingEnum) /// </summary> /// <param name="policePath"></param> private void PolicePathMovingStatements(PolicePath policePath) { if (!Stopped) { if (transform.position.z >= policePath.GetControlPoint(policePath.ChangePointIndex - 2).z) { if (transform.position.z >= policePath.GetControlPoint(policePath.ChangePointIndex).z) { if (policePathMoving == PolicePathMovingEnum.Stop) { return; } else { policePathMoving = PolicePathMovingEnum.ExitFromTheRoad; } } else { policePathMoving = PolicePathMovingEnum.SpeedReduction; } } } else { if (transform.position.z > policePath.GetControlPoint(policePath.StopPointIndex + 3).z) { if (didNotLeavePolicemanBefore) { policePath.Occupied = false; policePathMoving = PolicePathMovingEnum.ReturnToTheRoad; didNotLeavePolicemanBefore = false; } } } }