Example #1
0
 void OnCollisionEnter(Collision otherCollider)
 {
     switch (otherCollider.collider.tag)
     {
     case "Obstacle":
         movement.enabled = false;
         RandomalLevel.UpdateScore((int)otherCollider.transform.position.z + StaticData.StepsCount * StaticData.StepSize);
         FindObjectOfType <GameManager>().EndGame();
         break;
     }
 }
Example #2
0
 // Update is called once per frame
 void Update()
 {
     //update best score
     if (bestScoreText != null)
     {
         UpdateBestScore();
     }
     //quit key
     if (Input.GetKey(KeyCode.Q))
     {
         SceneManager.LoadScene(SceneManager.sceneCountInBuildSettings - 1);
     }
     //start key
     if (Input.GetKey(KeyCode.S) && !_gameHasStarted)
     {
         Debug.Log("s");
         _gameHasStarted = true;
         startText.text  = "0";
     }
     //only check if game has started
     if (!_gameHasStarted)
     {
         return;
     }
     //right key
     if (Input.GetKey(KeyCode.D))
     {
         rb.AddForce(vertical * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
     }
     //left key
     if (Input.GetKey(KeyCode.A))
     {
         rb.AddForce(-vertical * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
     }
     if (Input.GetKey(KeyCode.W) && flyTime > 0)
     {
         rb.AddForce(0, horizon * Time.deltaTime, 0, ForceMode.VelocityChange);
         if (--flyTime == 0)
         {
             flyObjUI.SetActive(false);
         }
         Debug.Log(flyObjUI.GetComponentInChildren <Slider>());
         flyObjUI.GetComponentInChildren <Slider>().value = (flyTime / _flyFull);
         Debug.Log(flyTime);
     }
     if (rb.position.y < 0 && !_gameHasEnded)
     {
         _gameHasEnded = true;
         Debug.Log(StaticData.StepsCount);
         RandomalLevel.UpdateScore((int)rb.position.z + StaticData.StepsCount * StaticData.StepSize);
         FindObjectOfType <GameManager>().EndGame();
     }
 }