示例#1
0
    public override void LateUpdate()
    {
        // get the state of the race from the race controller
        isRaceRunning = raceControl.raceRunning;

        if (isRaceRunning)
        {
            // check to see if we've crashed and are upside down/wrong(!)
            Check_If_Car_Is_Flipped();

            // make sure that gunControl has been told it can fire
            if (isAIControlled)
            {
                gunControl.canControl = true;
            }

            // we check for input in LateUpdate because Unity recommends this
            if (isAIControlled)
            {
                GetAIInput();
            }
            else
            {
                GetInput();
            }
        }
        else
        {
            if (isAIControlled)
            {
                // since the race is not running, we'll tell the AI gunControl not to fire yet
                gunControl.canControl = false;
            }
        }

        // tell the race controller to update
        raceControl.UpdateWaypoints();

        // see if our car is supposed to be held in-place
        CheckLock();

        // tell race control to see if we're going the wrong way
        raceControl.CheckWrongWay();

        // check to see if we're going the wrong way and act on it
        if (raceControl.goingWrongWay)
        {
            if (!isAIControlled)
            {
                GameController_MVD.Instance.UpdateWrongWay(true);
            }

            // if going the wrong way, compare time since wrong way started to see if we need to respawn
            if (raceControl.timeWrongWayStarted != -1)
            {
                timedif = Time.time - raceControl.timeWrongWayStarted;
            }

            if (timedif > resetTime)
            {
                // it's been x resetTime seconds in the wrong way, let's respawn this thing!
                Respawn();
            }
        }
        else if (!isAIControlled)
        {
            GameController_MVD.Instance.UpdateWrongWay(false);
        }

        accelMax = originalAccelMax;

        // do catch up if this car is falling behind in the race
        if (isRaceRunning && isAIControlled)
        {
            if (myRacePosition > 3)
            {
                // speed up
                accelMax = catchUpAccelMax;
            }
            else
            {
                accelMax = originalAccelMax;
            }

            // first place, let's slow you down!
            if (myRacePosition < 2)
            {
                accelMax = originalAccelMax * 0.25f;
                //motor=-1;
            }
        }

        // update the audio
        UpdateEngineAudio();
    }