The question is answered, right answer was accepted
In the next scene show the score using player prefab before next level
In my game i have it so when the player picks up an item the score increases ,there is a max number of items the level lets say ten , at the end of the level a new scene is loaded with some text and a button to load the next level what i'm looking to do is have the text say
" You scored (what they scored )out of 10 "
i have the message pop up but it always says 0 out of 10
Is there a way to go about getting the score.
here is the code im using to mange the score
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour {
static public int score;
public Text scoreText;
void Start ()
{
PlayerPrefs.GetInt ("scorePrefabs");
score=PlayerPrefs.GetInt ("scorePrefabs");
}
void Update ()
{
if (scoreText.name == "scoreText")
{
scoreText.text = "score: " + score;
}
PlayerPrefs.SetInt ("scorePrefabs", score);
}
}
and
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TextManager : MonoBehaviour {
public Text text;
void Start ()
{
int score = PlayerPrefs.GetInt ("Score", 0);
text.text="You Scored "+score.ToString()+ " out of 10";
}
}
Answer by KoenigX3 · Jan 12, 2017 at 05:51 PM
Whenever you pick up an item, you can increase a local integer variable. When you change the level, use:
PlayerPrefs.SetInt("score", scoreVariable);
(where scoreVariable is the variable which you have been increasing.)
The TextManager should work fine if you change it to "score".