//Wait for the car to stop before we generate a new path
    //or it might have passed the start position of the path when the path has been generated
    IEnumerator WaitForCarToStop()
    {
        //Get the car's current speed
        VehicleDataController carDataController = SimController.current.GetActiveCarData();

        //Will continue looping until the car has a lower speed then 5 km/h
        while (Mathf.Abs(carDataController.GetSpeed_kmph()) > 5f)
        {
            yield return(null);
        }

        //Now we need to check again if the target position is possible because we might have moved the mouse while the car was braking
        if (HasMouseCarValidPosition())
        {
            //Move the marker car to the end of the path so we know know where the path should end and at which heading
            Car carMouse = new Car(SimController.current.GetCarMouse(), SimController.current.GetActiveCarData());

            Transform carShowingEndPos = SimController.current.GetCarShowingEndPosTrans();

            carShowingEndPos.position = carMouse.carData.GetCenterPos(carMouse.rearWheelPos, carMouse.HeadingInRadians);
            carShowingEndPos.rotation = Quaternion.Euler(new Vector3(0f, carMouse.HeadingInDegrees, 0f));

            carShowingEndPos.gameObject.SetActive(true);


            //The car has stopped and the target is a valid positon, so try to generate a path
            StartCoroutine(GeneratePath(carMouse));

            yield break;
        }
        else
        {
            Debug.Log("The car cant move to this position");
        }
    }
예제 #2
0
    //
    // Update speed
    //

    //Dont need to update speed every frame
    private IEnumerator UpdateSpeedText()
    {
        while (true)
        {
            if (SimController.current != null)
            {
                //Get the speed in km/h
                VehicleDataController dataController = SimController.current.GetActiveCarData();

                float speed = dataController.GetSpeed_kmph();

                //float speed = 0f;

                //Round
                int speedInt = Mathf.RoundToInt(speed);

                //Display the speed
                speedText.text = speedInt + " km/h";
            }

            yield return(new WaitForSeconds(0.5f));
        }
    }