- Home /
Passing "best" to the other scene
Hello i have a problem about the passing data(distance/best distance) to the other scene there its the script what should i do. Can you guys correct this script?
public class meter : MonoBehaviour {
GUIText guitexty;
public GameObject player;
float beginPos;
float curPos;
public int multiplier=10;
// Use this for initialization
void Start () {
beginPos = player.transform.position.y;
guitexty = GetComponent<GUIText> ();;
}
// Update is called once per frame
void Update () {
curPos = player.transform.position.y - beginPos;
int distance = Mathf.RoundToInt (curPos * multiplier);
if (distance > PlayerPrefs.GetInt ("Best"))
PlayerPrefs.SetInt ("Best", distance);
guitexty.text = distance + "m /" + PlayerPrefs.GetInt ("Best") + "m";
}
}
Comment
What do you mean by distance?
if you mean like a high score of how far you got its easy...
Yes, high score. This script working but i want to know how to transfer "high scores(best distance) of character" to the other scene.
You're already saving it to PlayerPrefs. So you could just load it from PlayerPrefs in the Start function of an object that's created when the next scene starts.
You could even just access it putting PlayerPrefs.GetInt ("Best")
whenever you need it (which, again, is what you're already doing!).