- Home /
Get player script methods&variables from another script in another Scene
Hello i got a problem. I want to display player score that is in a scene. And i want to acces that script from antoher script in another scene just to display the score.
This is the class i want to inherit from:
public float scoreCalculation(){
score = 1;
random = random + Random.Range(min,max);
score =+ random + addScore;
return score;
}
public float getScore(){
float pScore = score;
return pScore;
}
And this is the class that i want to display the score in another scene.
public class guiDead : MonoBehaviour {
public GUIStyle style,style2;
public player score;
private float displayScore;
void start(){
score = GetComponentInParent<player>();
displayScore = score.getScore();
}
void OnGUI(){
GUI.Box(new Rect(200,200,200,200),"Sorry you died \n \n Your Score: " + displayScore,style);
if(GUI.Button(new Rect(200,450,100,100),"Retry",style2)){
Application.LoadLevel(1);
}
}
}
Can you guys please help me?
Answer by SnotE101 · Sep 02, 2014 at 01:50 AM
Try playerprefs. Its a built in way to access data through levels or scenes. Check it out here ==>http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Good luck!
Your answer
Follow this Question
Related Questions
Access to a variable inside a C# class 2 Answers
Macbook Pro Retina Display [Solved] 1 Answer
How to build a map from planes (walls, floors, ceilings)? 1 Answer
Why Is TextMesh Off by One ??? 0 Answers
What scene is loaded? How to tell... 2 Answers