コード例 #1
0
    void Update()
    {
        if (areControllsEnabled)
        {
            x = Input.GetAxis("Horizontal");

            if (Input.GetKeyUp(KeyCode.Escape))
            {
                gameManager.ShowMainMenuPrompt(true);
                escaped = true;
                gameManager.PauseTimer();
            }

            if (Input.GetKeyDown(KeyCode.Escape) && escaped)
            {
                gameManager.BackToMainMenu();
            }
            else if (!Input.GetKeyDown(KeyCode.Escape) && Input.anyKey && escaped)
            {
                gameManager.ShowMainMenuPrompt(false);
                escaped = false;
                if (timerController.GetTime() > 0)
                {
                    gameManager.ResumeTimer();
                }
            }
        }

        //-----------------------------
        // Car has enought fuel to move
        if (FuelManager.GetFuel() > 0 && areControllsEnabled)
        {
            z = Input.GetAxis("Vertical");
            Translate(z);

            if (z != 0)
            {
                Rotate(x * z);
            }
            //-----------------------------------------
            // Car run out of fuel while moving FORWARD
        }
        else if (FuelManager.GetFuel() <= 0 && z > 0)
        {
            z -= 0.4f * Time.deltaTime;
            Rotate(x * z);
            Translate(z);

            if (Input.GetAxis("Vertical") < 0f)
            {
                Translate(0);
                z = 0;
            }
            //------------------------------------------
            // Car run out of fuel while moving BACKWARD
        }
        else if (FuelManager.GetFuel() <= 0 && z < 0)
        {
            z += 0.4f * Time.deltaTime;
            Rotate(x * z);
            Translate(z);

            if (Input.GetAxis("Vertical") > 0f)
            {
                Translate(0);
                z = 0;
            }
        }

        if (Input.GetAxis("Vertical") != 0 && areControllsEnabled)
        {
            FuelManager.ConsumeFuel(fuelConsumption);
        }
    }