GameOver Score Counter
Hi,
How can I count the score from 0 to the reached score on the GameOver menu?
public Canvas gameOverMenu;
public Text score; //Default is 0
public void GameOver(){
StartCoroutine (OpenGameOverMenu ());
//score is a static float from the playerscript
score.text = Player.score.ToString(); //How can I count?
}
IEnumerator OpenGameOverMenu(){
yield return new WaitForSeconds (0.8f);
gameOverMenu.enabled = true;
}
Thanks
Answer by safak93 · Oct 02, 2015 at 05:27 PM
I made it. Maybe it will help someone.
Here is the script:
public enum GameState{Playing, GameOver};
public GameState currentGameState;
public float waitTime = 1.5f;
private float currentTime = 0;
public Canvas gameOverMenu;
public Text score;
//////////////////////////////////////////////////
public void GameOver(){
StartCoroutine (OpenGameOverMenu ());
currentGameState = GameState.GameOver;
}
IEnumerator OpenGameOverMenu(){
yield return new WaitForSeconds (0.8f);
gameOverMenu.enabled = true;
}
public void Update(){
if (currentGameState == GameState.GameOver && Player.score > 1) {
currentTime += Time.deltaTime;
score.text = Mathf.FloorToInt (Mathf.Lerp (0, Player.score, currentTime / waitTime)).ToString ();
}
else if (currentGameState == GameState.GameOver) {
score.text = Player.score.ToString();
}
}
Answer by Ali-hatem · Sep 30, 2015 at 02:24 PM
public void GameOver()
{
if ( Player.score >= 5 )//if that how you enter the player class
{
StartCoroutine (OpenGameOverMenu ());
}
}
Thanks for your answer. Unfortunately that's not what I want to do.
If the player dies the function "_menu$$anonymous$$anager.GameOver();" will called and then the GameOver menu will be opened with "StartCoroutine (OpenGameOver$$anonymous$$enu ());". Until here everything works how I want it.
After that there is a score text on the menu to display the reached score - >score.text = Player.score.ToString();. So I want to display the score with a counter. As an example: Lets say the Player.Score is "5" and the player dies. I want to display it, after the GameOver menu is open, with a counter, begins at 0 and stops at 5 -> 1,2,3,4,5.
I hope I could explain it.