示例#1
0
    IEnumerator GoRight(CrossRoad crossRoad)
    {
        executingCoroutine = true;
        crossRoad.OccupiedByMe(gameObject.GetInstanceID());
        Vector3 currentRotation = transform.rotation.eulerAngles;
        //float normalizedAngle = NormalizeDegrees(currentRotation.y + 90);
        Vector3 rotation = new Vector3(currentRotation.x, currentRotation.y + 90, currentRotation.z);

        currentSpeed = 5;
        // Go straigth
        yield return(new WaitForSeconds(1.8f));

        var fromAngle = transform.rotation;
        var toAngle   = Quaternion.Euler(rotation);

        while (Quaternion.Angle(fromAngle, toAngle) > 0)
        {
            transform.Rotate(new Vector3(0, 1f, 0));
            fromAngle = transform.rotation;
            yield return(new WaitForSeconds(Time.deltaTime));
        }
        transform.rotation = Quaternion.Euler(currentRotation.x, NormalizeDegrees(currentRotation.y + 90), currentRotation.z);

        // Go straight to exit cross
        yield return(new WaitForSeconds(1.5f));

        executingCoroutine = false;
        currentSpeed       = maxSpeed;
        crossRoad.FreeCrossRoad();
    }
示例#2
0
    IEnumerator MakeUTurnOnCross(CrossRoad crossRoad)
    {
        executingCoroutine = true;
        crossRoad.OccupiedByMe(gameObject.GetInstanceID());
        currentSpeed = 5;
        Vector3 currentRotation = transform.rotation.eulerAngles;
        Vector3 rotation        = new Vector3(currentRotation.x, currentRotation.y - 180, currentRotation.z);

        // Do turn
        var fromAngle = transform.rotation;
        var toAngle   = Quaternion.Euler(rotation);

        while (Quaternion.Angle(fromAngle, toAngle) > 1)
        {
            transform.Rotate(new Vector3(0, -1f, 0));
            fromAngle = transform.rotation;
            yield return(new WaitForSeconds(Time.deltaTime));
        }
        transform.rotation = Quaternion.Euler(currentRotation.x, NormalizeDegrees(currentRotation.y - 180), currentRotation.z);


        // Go straight to exit cross
        yield return(new WaitForSeconds(2));

        currentSpeed       = maxSpeed;
        executingCoroutine = false;
        crossRoad.FreeCrossRoad();
    }
示例#3
0
    IEnumerator CrossStraight(CrossRoad crossRoad)
    {
        executingCoroutine = true;
        crossRoad.OccupiedByMe(gameObject.GetInstanceID());
        currentSpeed = maxSpeed;
        // Go straight to exit cross
        yield return(new WaitForSeconds(4));

        executingCoroutine = false;
        crossRoad.FreeCrossRoad();
    }