Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Score counter doesn't work after you die

$
0
0
Hi there, so i am making a 2d endless runner game and i have a score counter. After i die my score should display ,but that isnt the case the score is 0 after i die and is different before i die. so this is mt script for the score displaying after i died. using UnityEngine; using System.Collections; public class gameover : MonoBehaviour { int score = 0; void Start () { score = PlayerPrefs.GetInt( "Score"); } void OnGUI() { GUI.Label (new Rect(Screen.width / 2 - 20, 150, 100, 50), "Score: " +score); if(GUI.Button(new Rect(Screen.width / 2 -30, 350, 60, 30), "Retry? ")) { Application.LoadLevel (0); } } } and this is the script that generates the score using UnityEngine; using System.Collections; public class headsupdisplay : MonoBehaviour { float playerScore = 0; // Update is called once per frame void Update () { playerScore += Time.deltaTime; } public void IncreaseScore(int amount) { playerScore += amount; } void OnGUI() { GUI.Label(new Rect(10, 10, 100, 30), "Score: " + (int)(playerScore * 3.1413658)); } } There are no error and i dont think i did something wrong. Can anyone help me?

Viewing all articles
Browse latest Browse all 7934

Trending Articles