Beispiel #1
0
 void HandleItemPickup(ItemType itemType)
 {
     if (itemType == ItemType.NITROUS)
     {
         nitrousAmt = Mathf.Clamp(nitrousAmt + nitrousIncrementAmt, 0, 100);
         OnNitrousPickup?.Invoke(nitrousIncrementAmt);
     }
     else if (itemType == ItemType.SHIELD)
     {
         shieldActive = true;
         shield.SetActive(true);
     }
 }
Beispiel #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (timeSlow)
            {
                timeSlow            = false;
                Time.timeScale      = 1f;
                Time.fixedDeltaTime = 0.02f;
            }
            else
            {
                timeSlow            = true;
                Time.timeScale      = slowTimeSpeed;
                Time.fixedDeltaTime = 0.02f * slowTimeSpeed;
            }
        }
        if (transform.position.y < -10 || Input.GetKeyDown(KeyCode.R))
        {
            transform.rotation = Quaternion.identity;
            sphereRB.velocity  = Vector3.zero;
            sphereRB.drag      = normalDrag;

            sphereRB.gameObject.transform.position = startPos;
            transform.position = startPos;

            OnGameOver?.Invoke();
            Debug.Log("GAME OVER!");
        }

        if (isGrounded && Time.timeScale == 1)
        {
            speed += speedIncrement;
            OnSpeedChange?.Invoke(speed);
            //speedText.text = speed.ToString("F2") + "\nkm/hr";
        }

        isDrifting = Input.GetButton("Jump");

        if (Input.GetKey(KeyCode.X) && nitrousAmt > 0f)
        {
            nitrousAmt            -= .06f;
            nitrousSpeedMultiplier = 2f;
            OnNitrousPickup?.Invoke(-.06f);

            // activate exhaust flames
            foreach (var n in nitrousFX)
            {
                n.gameObject.SetActive(true);
                n.Play();
            }
        }
        else
        {
            nitrousSpeedMultiplier = 1f;

            // deactivate exhaust flames
            foreach (var n in nitrousFX)
            {
                n.Pause();
                n.gameObject.SetActive(false);
            }
        }
    }