示例#1
0
 // Use this for initialization
 void Start()
 {
     agent = GetComponent <NavMeshAgent>();
     SetRayToCast();
     GetFirstIntersection();
     intersection.AddCarToIntersection();
     FindInitialWaypoint();
     GoToInitialWaypoint();
     startSpeed = agent.speed;
     StartCoroutine(FenderBenderPreventor());
     StartCoroutine(MoveToNextWayPoint());
 }
    public Vector3 NextWaypoint(ref CarHeading heading, out IntersectionController intersection, AI_CarController car)
    {
        carsCount--;
        RemoveLightListener(heading, car);
        Vector3   waypoint = new Vector3();
        Direction dir      = Direction.Undefined;
        int       compare  = 10;

        foreach (var neighbor in neighbors)
        {
            if (neighbor.Value.carsCount < compare)
            {
                if (NoGoDirection(heading) == neighbor.Key)
                {
                    continue;
                }
                else
                {
                    compare = neighbor.Value.carsCount;
                    dir     = neighbor.Key;
                }
            }
        }
        intersection = neighbors[dir];
        intersection.AddCarToIntersection();
        switch (dir)
        {
        case Direction.North:
            waypoint = intersection.North.position;
            heading  = CarHeading.North;
            break;

        case Direction.South:
            waypoint = intersection.South.position;
            heading  = CarHeading.South;
            break;

        case Direction.East:
            waypoint = intersection.East.position;
            heading  = CarHeading.East;
            break;

        case Direction.West:
            waypoint = intersection.West.position;
            heading  = CarHeading.West;
            break;
        }
        intersection.AddCarToStreetLightEvent(heading, car);
        return(waypoint);
    }