Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (gameManager == null || vehiclePhysicsController == null || vehicleRenderController == null)
        {
            return;
        }

        // Don't burn fuel if physics isn't running
        if (false == vehiclePhysicsController.IsRunning())
        {
            return;
        }

        float currentFuel = gameManager.GetCurrentFuel() - Time.deltaTime * fuelBurnSpeed;

        gameManager.SetCurrentFuel(currentFuel);

        // TODO: Should play a warning sound (fast beep?) shortly before we run out (maybe flash the UI display?)
        if (currentFuel < 0)
        {
            vehicleRenderController.OnPlayerDeath();
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (vehiclePhysicsController == null)
        {
            return;
        }

        // Prevent any ramps before the player starts moving
        if (false == vehiclePhysicsController.IsRunning())
        {
            return;
        }

        // Can only select and place ramps while on the ground
        if (vehiclePhysicsController.IsGrounded())
        {
            // User selects a ramp by pressing down a key
            // User places a ramp by releasing the same key

            if (false == isRampSelected)
            {
                if (Input.GetKey(KeyCode.Alpha1))
                {
                    isRampSelected = true;
                    rampGhost      = resourceManager.GetOrCreateSmallRamp();
                    rampKeyCode    = KeyCode.Alpha1;
                }
                else if (Input.GetKey(KeyCode.Alpha2))
                {
                    isRampSelected = true;
                    rampGhost      = resourceManager.GetOrCreateMediumRamp();
                    rampKeyCode    = KeyCode.Alpha2;
                }
                else if (Input.GetKey(KeyCode.Alpha3))
                {
                    isRampSelected = true;
                    rampGhost      = resourceManager.GetOrCreateLargeRamp();
                    rampKeyCode    = KeyCode.Alpha3;
                }

                // If ramp was selected, give it a ghost-like appearance
                if (isRampSelected)
                {
                    Renderer[] renderers = rampGhost.GetComponentsInChildren <Renderer>();
                    foreach (Renderer renderer in renderers)
                    {
                        renderer.material = ghostMaterial;
                    }
                }
            }
            else if (false == isRampPlaced)
            {
                if (Input.GetKeyUp(rampKeyCode))
                {
                    isRampPlaced = true;
                }

                // If ramp was placed, remove the ghost appearance
                if (isRampPlaced)
                {
                    Renderer[] renderers = rampGhost.GetComponentsInChildren <Renderer>();
                    foreach (Renderer renderer in renderers)
                    {
                        renderer.material = rampMaterial;
                    }
                }
            }

            // Make the ghost precede the player's position
            if (isRampSelected && false == isRampPlaced)
            {
                rampGhost.transform.position = vehiclePhysicsController.transform.position + Vector3.forward * ghostOffset;
            }
        }
        else if (vehiclePhysicsController.IsAirborne())
        {
            // Reset once we hit the air
            isRampSelected = false;
            isRampPlaced   = false;
            rampGhost      = null;
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (gameManager == null || vehiclePhysicsController == null || vehicleRenderController == null)
        {
            return;
        }

        if (false == vehiclePhysicsController.IsRunning())
        {
            return;
        }

        if (vehiclePhysicsController.IsGrounded())
        {
            isCountdownActive  = false;
            isCountdownExpired = false;
        }

        if (false == isCountdownActive && false == isCountdownExpired)
        {
            if (vehiclePhysicsController.IsAirborne())
            {
                isCountdownActive  = true;
                startCountdownTime = Time.time;

                currentKeyComboIndex = 0;

                keyCombo = keyCombos[(int)(Random.value * keyCombos.Length)];

                keyComboPrompt.SetKeyComboText(GetKeyComboText(keyCombo));
                keyComboPrompt.SetMaxTime(availableCountdownTime);
                keyComboPrompt.SetCurrentTime(availableCountdownTime);
                keyComboPrompt.Show();
            }
        }

        if (isCountdownActive)
        {
            KeyCode nextKeyCode = keyCombo[currentKeyComboIndex];
            if (Input.GetKeyDown(nextKeyCode))
            {
                currentKeyComboIndex++;
                if (currentKeyComboIndex >= keyCombo.Length)
                {
                    // Nailed it!
                    DoTrick();

                    isCountdownActive  = false;
                    isCountdownExpired = true;

                    keyComboPrompt.Hide();
                }
            }
            else if (Input.anyKeyDown)
            {
                // Reset key combo if any other key was pressed
                currentKeyComboIndex = 0;
            }

            float remainingCountdownTime = availableCountdownTime - (Time.time - startCountdownTime);
            keyComboPrompt.SetCurrentTime(remainingCountdownTime);

            if (remainingCountdownTime <= 0)
            {
                isCountdownActive  = false;
                isCountdownExpired = true;

                keyComboPrompt.Hide();
            }
        }
    }