Пример #1
0
        private void Update()
        {
            if (input != null && controller != null)
            {
                if (input.IsBreakOn)
                {
                    if (!Mathf.Approximately(controller.StraightVelocityMagnitude, 0.0f))
                    {
                        if (controller.IsMovingForward)
                        {
                            controller.Gas(0.0f);
                            controller.Brake(1.0f);
                        }
                        else
                        {
                            // Gas backwards
                            controller.Gas(-1.0f);
                            controller.Brake(0.0f);
                        }
                    }
                    else // carEngine.IsStationary, 0 straight(front back) velocity
                    {
                        // Gas backwards
                        controller.Gas(-1.0f);
                        controller.Brake(0.0f);
                    }
                }
                else if (input.IsGasOn)
                {
                    controller.Gas(1.0f);
                    controller.Brake(0.0f);
                }
                else
                {
                    controller.Gas(0.0f);
                    controller.Brake(0.0f);
                }

                steering = input.Horizontal;

                controller.Steer(steering);
            }
        }
Пример #2
0
        private void Update()
        {
            if (input != null && controller != null)
            {
                if (input.IsBreakOn)
                {
                    if (!Mathf.Approximately(controller.StraightVelocityMagnitude, 0.0f))
                    {
                        if (controller.IsMovingForward)
                        {
                            controller.Gas(0.0f);
                            controller.Brake(1.0f);
                        }
                        else
                        {
                            // Gas backwards
                            controller.Gas(-1.0f);
                            controller.Brake(0.0f);
                        }
                    }
                    else // carEngine.IsStationary, 0 straight(front back) velocity
                    {
                        // Gas backwards
                        controller.Gas(-1.0f);
                        controller.Brake(0.0f);
                    }
                }
                else if (input.IsGasOn)
                {
                    controller.Gas(1.0f);
                    controller.Brake(0.0f);
                }
                else
                {
                    controller.Gas(0.0f);
                    controller.Brake(0.0f);
                }

                if (input.IsLeftOn)
                {
                    if (steering > -1.0f)
                    {
                        if (steering > 0.0f)
                        {
                            steering = 0.0f;
                        }

                        steering -= steeringInputRate * Time.deltaTime;
                        if (steering < -1.0f)
                        {
                            steering = -1.0f;
                        }
                    }
                }
                else if (input.IsRightOn)
                {
                    if (steering < 1.0f)
                    {
                        if (steering < 0.0f)
                        {
                            steering = 0.0f;
                        }

                        steering += steeringInputRate * Time.deltaTime;
                        if (steering > 1.0f)
                        {
                            steering = 1.0f;
                        }
                    }
                }
                else
                {
                    steering = 0.0f;
                }

                controller.Steer(steering);
            }
        }