// Update is called once per frame void Update() { if (ScoreList.getList().Count > 0) { if (ScoreList.getList()[0] < playerController.transform.position.z && !highscoreNotificationCreated) { highscoreNotificationCreated = true; instantiateHighscoreNotification(); } } else { instantiateHighscoreNotification(); } // if enter key or button 0 pressed, and in tutorial, launch game if ((Input.GetKeyDown("joystick button 0") || Input.GetKeyDown(KeyCode.Return)) && tutorial) { tutorial = false; Destroy(instructions); Destroy(image); displayInformations(); MusicManager.play(getRandomMusic(), 0.5f, 0.5f); } else if (!tutorial) { speed.text = "Speed: " + Mathf.Round(playerController.getSpeed() * 10f) / 10f + " km/h"; distance.text = "Distance: " + Mathf.Round(playerController.getDistance() * 10f) / 10f + " m"; } }
public void death() { ScoreList.add(distance); if (ScoreList.getList()[0] == distance) { onNewHighScore(); } dead = true; }
// Update is called once per frame void LateUpdate() { // if the button hasn't been createed yet and if the player's dead if (playerController.isDead() && !created) { created = true; image = Instantiate(imagePrefab, new Vector3(Screen.width / 2, Screen.height / 2, 0), Quaternion.identity) as Image; image.color = new Color32(200, 200, 200, 175); image.transform.SetParent(hudCanvas.transform); buttonClone = Instantiate(endButton, new Vector3(Screen.width / 2 - 75, Screen.height / 2, 0), Quaternion.identity) as Button; buttonClone.transform.SetParent(hudCanvas.transform); scores = Instantiate(highscoresTextPrefab, new Vector3(Screen.width / 2 + 75, Screen.height / 2, 0), Quaternion.identity) as Text; string scoresText = "Highscores:\n\n"; int count = (ScoreList.getList().Count > 5 ? 5 : ScoreList.getList().Count); for (int i = 0; i < count; i++) { scoresText += ((Mathf.Round(ScoreList.getList()[i]) * 10f) / 10f).ToString() + " m\n"; } scores.text = scoresText; scores.transform.SetParent(hudCanvas.transform); return; } // simulates click on button from joystick or on return key down if ((Input.GetKeyDown("joystick button 0") || Input.GetKeyDown(KeyCode.Return)) && buttonClone != null) { buttonClone.onClick.Invoke(); } // if the player isn't dead and if we pressed either return or button 0 from joystick (and if we're not in tutorial) if ((Input.GetKeyDown("joystick button 0") || Input.GetKeyDown(KeyCode.Return)) && !playerController.isDead() && !playerController.getHUDManager().inTutorial()) { if (pause) { pause = false; if (tempPauseText != null) { Destroy(tempPauseText.gameObject); } playerController.startRunning(); MusicManager.unpause(); } else { pause = true; tempPauseText = instantiatePauseText(); playerController.stopRunning(); MusicManager.pause(); } } }
// Use this for initialization void Start() { int count = (ScoreList.getList().Count >= 5 ? 5 : ScoreList.getList().Count); for (int i = 0; i < count; i++) { offsets.Add(ScoreList.getList()[i]); } currentCylinder = CG.newCylinder(new Vector3(0, 0, 0), Quaternion.identity, true).transform; frontCylinder = CG.newCylinder(new Vector3(0, 0, cylinderLength), Quaternion.identity).transform; TextMesh textMesh; for (int i = 0; i < offsets.Count; i++) { textMesh = Instantiate(positionTextPrefab, new Vector3(0, 0, offsets[i]), Quaternion.identity) as TextMesh; switch (i) { case 4: textMesh.text = "5th"; break; case 3: textMesh.text = "4th"; break; case 2: textMesh.text = "3rd"; break; case 1: textMesh.text = "2nd"; break; case 0: textMesh.text = "1st"; break; } } }