示例#1
0
    private void FixedUpdate()
    {
        if (normalCamPos == Vector3.zero)
        {
            normalCamPos = theCam.transform.localPosition;
            normalRot    = theCam.transform.localRotation.eulerAngles;
            backCamPos   = normalCamPos;
            backCamPos.z = backCamPos.z * -1;
        }

        // pass the input to the car!
        float h         = Input.GetAxis("Horizontal");
        float v         = Input.GetAxis("Vertical");
        float handbrake = Input.GetAxis("Jump");

        if (m_Car != null)
        {
            m_Car.Move(h, v, v, handbrake);
        }
        else if (m_Car2 != null)
        {
            m_Car2.Move(h, v, v, handbrake);
        }



        if (Input.GetKeyDown(KeyCode.Delete))
        {
            m_Car.Flip();
        }

        if ((Input.GetKey(KeyCode.RightShift)) && shiftPressed == false)
        {
            theCam.transform.localPosition = backCamPos;
            Vector3 backRot = normalRot;
            backRot.y = backRot.y + 180;
            theCam.transform.localRotation = Quaternion.Euler(backRot);
            shiftPressed = true;
            Debug.Log("Look back");
        }
        else if ((Input.GetKey(KeyCode.RightShift) == false) && shiftPressed)
        {
            shiftPressed = false;
            theCam.transform.localPosition = normalCamPos;
            theCam.transform.localRotation = Quaternion.Euler(normalRot);
            Debug.Log("Look forward");
        }

        if (Input.GetKey(KeyCode.M))
        {
            m_Car.SetShooting(0, true);
        }
        else
        {
            m_Car.SetShooting(0, false);
        }
    }
示例#2
0
    private void FixedUpdate()
    {
        // Statt Input automatisch fahren, entsprechend den Einstellungen, die in der GUI ausgewählt werden

        // pass the input to the car!
        float h         = 0f;
        float v         = 0f;
        float handbrake = 0f;

        switch (driveMode)
        {
        case AutoDriveMode.STOP:
            if (m_Car.CurrentSpeed > 1f)
            {
                v = -1f;
                h = 0f;
            }
            else if (m_Car.CurrentSpeed < -1f)
            {
                v = 1f;
                h = 0f;
            }
            else
            {
                v = 0f;
                h = 0f;
            }
            //handbrake = 1f;
            break;

        case AutoDriveMode.ACC_DEC:
            handbrake = 0f;
            switch (state)
            {
            case 0:
                counter += Time.deltaTime;
                v        = 1f;
                h        = 0f;
                //if (counter > 6f)
                if (m_Car.CurrentSpeed > Speed)
                {
                    state   = 1;
                    counter = 0f;
                }
                break;

            case 1:
                counter += Time.deltaTime;
                v        = -1f;
                h        = 0f;
                if (m_Car.CurrentSpeed < 1f)
                {
                    state   = 0;
                    counter = 0f;
                }
                break;
            }
            break;

        case AutoDriveMode.LEFT_TURN:
            handbrake = 0f;
            if (m_Car.CurrentSpeed > Speed)
            {
                v = 0f;
            }
            else
            {
                v = 1f;
            }
            h = SteerAngle;
            break;

        case AutoDriveMode.RIGHT_TURN:
            handbrake = 0f;
            if (m_Car.CurrentSpeed > Speed)
            {
                v = 0f;
            }
            else
            {
                v = 1f;
            }
            h = -SteerAngle;
            break;

        case AutoDriveMode.ALTERNATE:
            handbrake = 0f;
            if (m_Car.CurrentSpeed > Speed)
            {
                v = 0f;
            }
            else
            {
                v = 1f;
            }
            switch (state)
            {
            case 0:
                counter += Time.deltaTime;
                h        = SteerAngle;
                if (counter > 2f)
                {
                    state   = 1;
                    counter = 0f;
                }
                break;

            case 1:
                counter += Time.deltaTime;
                h        = -SteerAngle;
                if (counter > 2f)
                {
                    state   = 0;
                    counter = 0f;
                }
                break;
            }
            break;

        case AutoDriveMode.STRAIGHT:
            handbrake = 0f;
            if (m_Car.CurrentSpeed > Speed)
            {
                v = 0f;
            }
            else
            {
                v = 1f;
            }
            h = 0f;
            break;
        }


        if (driveModeJustChanged)
        {
            driveModeJustChanged = false;
            v         = -1f;
            handbrake = 0f;
            h         = 0f;
        }


        if (m_Car != null)
        {
            m_Car.Move(h, v, v, handbrake);
        }



        if (Input.GetKeyDown(KeyCode.Delete))
        {
            m_Car.Flip();
        }
    }