- Home /
How do I display the final score?
I'm making a simple tunnel game and I have a simple scoring system. Its basically just a counter. My GUI script works perfectly however I can't seem to figure out how to display the results when the player dies( I call an Application.LoadLevel() on some sort of Collison or Trigger throughout the game) and then the game starts over. Here's my script:
var r : float = 1;
var g : float = 0; var b : float = 0; var a : float = 1;
function Start() { var i : int = 0; for(i = 0; i<=4500; i++){
guiText.text = "SCORE: "+i;
var color : Color = Color (r, g, b, a);
// Adjusts material color of text r,g,b,a(alpha).
guiText.material.color = color;
yield WaitForSeconds(.05);
}
}
How do I display the score or the counter at the "time" the player dies?
Answer by Yanger_xy · Jul 11, 2011 at 09:43 AM
you can define a bool variable to record whether the player is died, and a variable to record the score like this:
var : bool _isDied = false;
var : float _score = 0;
then in your OnGUI function, check the bool variable, if it is true, show the score.
function OnGUI()
{
if(_isDied == true)
{
GUILayout.Label(_score);
}
}
good luck!
Your answer
![](https://koobas.hobune.stream/wayback/20220612140710im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Score Counter Help 2 Answers
Lerpz Escapes question 1 Answer
Score/Points when player kills enemy (multiplayer) 1 Answer
Score Help (Im new) 1 Answer
Score display not working 1 Answer