Beispiel #1
0
    public void TestPark()
    {
        if (Random.Range(0.0f, 100.0f) < parkChance_)
        {
            Road         road    = car_.GetCurRoad().GetComponent <Road>();
            ParkingSpace parking = null;
            if (road)
            {
                GameObject space = road.GetParkingSpace();
                if (space)
                {
                    parking = space.GetComponent <ParkingSpace>();
                }
            }

            if (parking)
            {
                car_.SetState(CarState.CS_PARKING);
                parking.SetAvailable(false);

                car_.ClearTargets();
                List <Vector3> newTargets = parking.GetEnterTargets();
                foreach (Vector3 target in newTargets)
                {
                    car_.AddTarget(target);
                }

                curParking_ = parking;
            }
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (car_.GetState() == CarState.CS_PARKED)
        {
            parkTimer_ += Time.deltaTime;
            if (parkTimer_ > parkingTime_)
            {
                car_.SetState(CarState.CS_DEPARKING);
                car_.ClearTargets();
                List <Vector3> newTargets = curParking_.GetExitTargets();
                foreach (Vector3 target in newTargets)
                {
                    car_.AddTarget(target);
                }
                parkTimer_ = 0;
            }
        }
        else if (car_.GetState() == CarState.CS_MOVING)
        {
            if (curParking_)
            {
                curParking_.SetAvailable(false);
                curParking_ = null;
            }
        }

        //check if the car has stopped
        if (body_.velocity.magnitude < 0.1f)
        {
            //check if the car should be going
            if (car_.GetCurRoad().GetComponent <Road>().GetEnd().Find("TrafficLight").GetComponent <TrafficLight>().GetSignal() == Signals.S_GO)
            {
                if (vision_)
                {
                    //make sure the car isn't honking at itself
                    if (vision_.ObjectAhead())
                    {
                        TestImpatience();
                    }
                }
            }
        }

        if (impatience_ > baseImpatience_)
        {
            impatience_ -= impatienceIncSpeed_ * Time.deltaTime;
        }
        else
        {
            impatience_ = baseImpatience_;
        }
    }