예제 #1
0
 private void OnCollisionEnter(Collision collisionInfo) //collision detection
 {
     if (collided)                                      //while collided, don't register another collision; grant the player temporary invincibility so they can register that they lost a life
     {
         return;
     }
     if (collisionInfo.collider.CompareTag("Obstacle"))
     {
         tickSource.PlayOneShot(audio2, 0.6f);
         if (collideReminderTimer == 0) //only display the collider reminder once; collideReminderTimer is updated in the Update function
         {
             CollideReminder.SetActive(true);
         }
         else if (CollideReminder.activeSelf && SceneManager.GetActiveScene() == SceneManager.GetSceneByName("Tutorial")) //a second collision resets the countdown in tutorial mode
         {
             collideReminderTimer = 0;
         }
         currentLife--;
         uiManager.UpdateLives(currentLife);                                          //display new life count
         if (SceneManager.GetActiveScene() != SceneManager.GetSceneByName("Sandbox")) //sandbox doesn't even slow down for collisions, let alone lose the game
         {
             if (currentLife <= 0)
             {
                 if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("Game"))
                 {
                     uiManager.SaveSettingsAndHighScoreToTextFile(money); //score and settings are saved upon death
                 }
                 carRev.mute = true;
                 tickSource.PlayOneShot(audio3, 2f);
                 uiManager.gameOverPanel.SetActive(true);
                 CoinReminder.SetActive(false);
                 CollideReminder.SetActive(false);
                 ControlReminder.SetActive(false);
                 SpeedReminder.SetActive(false);
                 Invoke("GoBackToMenu", 3f); //upon losing all lives, display GameOverPanel for 3 seconds before returning to menu
             }
             else
             {
                 speed = minSpeed; //reset speed upon a collision
                 StartCoroutine(Collided());
             }
         }
         else //in sandbox mode
         {
             //speed = minSpeed; //could set speed back to the lower bound
             speed -= 3; //could decrement the speed by a constant (arbitrary) amount
             //speed -= 0.1f * (speed - minSpeed); //could decrement the speed by some function
             if (speed < minSpeed)
             {
                 speed = minSpeed;
             }
             //could leave the speed alone
         }
     }
 }
예제 #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Money"))
     {
         if (SceneManager.GetActiveScene() != SceneManager.GetSceneByName("Tutorial")) //tutorial mode doesn't have a coin reminder
         {
             CoinReminder.SetActive(false);
         }
         tickSource.PlayOneShot(audio1, 0.2f);
         money++;
         uiManager.UpdateMoney(money);
         //other.transform.parent.gameObject.SetActive(false); //if the money prefab had a parent object (money holder); now-deprecated way to remove collected money
         //other.transform.gameObject.SetActive(false); //now-deprecated way to remove collected money
     }
 }
예제 #3
0
 // Start is called before the first frame update
 void Start()
 {
     controller    = GetComponent <CharacterController>();
     speed         = minSpeed; //car starts off slow
     collidedValue = Shader.PropertyToID("_CollidedValue");
     uiManager     = FindObjectOfType <UIManager>();
     ControlReminder.SetActive(true);
     SpeedReminder.SetActive(true);
     if (SceneManager.GetActiveScene() != SceneManager.GetSceneByName("Tutorial")) //tutorial mode doesn't have a coin reminder
     {
         CoinReminder.SetActive(true);
     }
     AudioSource[] ticksources = GetComponents <AudioSource>();
     tickSource = ticksources[0];
     audio1     = ticksources[0].clip;
     audio2     = ticksources[1].clip;
     audio3     = ticksources[2].clip;
     carRev     = ticksources[3];
     this.updateCarModel((int)uiManager.carModel.value);
 }