I have a game where you collect artifacts and colliding with each artifact gives you a score in the top right corner of the screen. What I want is to have the total score the player achieved on level 1 and the total score the player achieved on level 2 to show up in the top right corner when the player completes level 2. Not sure what functions do this.
Here is my code:
Final is level1 and Final1 is level2 (I didn’t use this in the code, just thought I would show this jus in case you need to know to figure my problem out)
colliding with backdoor2 leads to Winscreen2 which is the scene I want to show the score
var Scores : String = "Bob";
//svar Scores : float = 0.0;
private var scoreText:GUIText;
public var score:int;
public var level:String;
public var sound4: AudioClip;
public var Metal_Impact_Hollow: AudioClip;
public var swap: AudioClip;
function Start ()
{
//intialize our variables listed
//Scores = PlayerPrefs.GetFloat("Coin");
score = 0;
scoreText = GameObject.Find("GUI_Score").GetComponent(GUIText);
//call update function to update text
UpdateScoreText();
}
function UpdateScoreText()
{
//update the GUI Text on screen
scoreText.text = "Score: " + score;
}
function OnGUI()
{
if (Application.loadedLevelName == "WinScreen")
GUILayout.Label("Score: " + score);
}
/*function Awake()
{
DontDestroyOnLoad(this);
}*/
function OnCollisionEnter(c:Collision)
{
if (c.gameObject.name == "vase" )
{
Destroy(c.gameObject); // destroys the thing this script bumped into
score += 100;
UpdateScoreText();
Debug.Log("vase");
audio.Play();
}
if (c.gameObject.name == "shield" )
{
Destroy(c.gameObject); // destroys the thing this script bumped into
score += 500;
UpdateScoreText();
audio.Play();
}
if (c.gameObject.name == "foxmask2" )
{
Destroy(c.gameObject); // destroys the thing this script bumped into
score += 900;
UpdateScoreText();
audio.Play();
}
if (c.gameObject.name == "boots2" )
{
Destroy(c.gameObject); // destroys the thing this script bumped into
score += 200;
UpdateScoreText();
audio.Play();
}
if (c.gameObject.name == "backdoor" )
{
Application.LoadLevel("WinScreen");
UpdateScoreText();
}
if (c.gameObject.name == "Cube" )
{
Application.LoadLevel("LoseScreen");
audio.Play();
}
if (c.gameObject.name == "Cube5" )
{
Application.LoadLevel("LoseScreen2");
audio.Play();
}
if (c.gameObject.name == "Cube2" )
{
Application.LoadLevel("LoseScreen");
audio.Play();
}
if (c.gameObject.name == "Cube3" )
{
Application.LoadLevel("LoseScreen2");
audio.Play();
}
if (c.gameObject.name == "backdoor2" )
{
Application.LoadLevel("WinScreen2");
UpdateScoreText();
}
}