Question by
BananaSmith · Nov 08, 2015 at 06:40 AM ·
scenescore
How to show score another scene ? And reset the score when the restart scene?
Well, I'm beginner in unity and I am using this script to the score and record . When my character dies he carries the Game Over Scene , and only shows the record , the score is reset. As for the score appears on the scene Game Over? And how do I score zero when the "Play" scene restart ?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Manager : MonoBehaviour {
public Text Highscore;
public Text Score;
public int score = 0;
// Use this for initialization
void Start () {
Highscore.text = " " + PlayerPrefs.GetInt ("Highscore");
Score.text = " " + score;
}
// Update is called once per frame
void Update () {
if (score > PlayerPrefs.GetInt ("Highscore")) {
PlayerPrefs.SetInt("Highscore", score);
}
Score.text = " " + score;
}
}
Comment
Answer by OctoMan · Nov 08, 2015 at 07:58 AM
Not excactly sure what you are looking for.
When you start your gamescene you set score to 0;
void Start()
{
score = 0;
}
When your game is complete you compare score with highscore. As you did already.
Answer by Ali-hatem · Nov 08, 2015 at 08:12 AM
//attach your script to empty game object and make it prefab & add it to any scene you want to show your score in
public class Manager : MonoBehaviour {
public static Manager man; //make the class static you can access any where.
void Awake () //add this to your script
{
if (man == null)
{
DontDestroyOnLoad(gameObject);
man = this;
}
else if (man != this)
{
Destroy(gameObject);
}
}
//now in the button wher you reset the scene or in start
Manager.man.score = 0;