How to reset GUI score after falling down?

hi , i’m trying to make a ball game. I need a help. There are coins and when i pick coins, i gain 1 point. For example , if i pick 2 coins, i have 2 points and when i fall down, episode starts again from the beginning but my score is still 2. it must be 0 after fall down. how can i reset my score after fall down ? how can i solve this? what should i add to my codes?

my scripts :
my GUI

#pragma strict

  static var currentScore : int = 0;
  
  var offsetY : float = 40;
  var sizeX : float = 100;
  var sizeY : float = 40;
  
  function OnGUI () {
           GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "Score: " + currentScore);
 
}

my coin script :

#pragma strict

var coinEffect : Transform;
var coinValue = 1;

function OnTriggerEnter (info : Collider)
{
	if (info.tag == "Player")
	{
        GameMaster.currentScore += coinValue;
		var effect = Instantiate(coinEffect, transform.position, transform.rotation) ;
		Destroy(effect.gameObject, 3);
		Destroy(gameObject);
	
	}
}   

and lastly, fall down script

#pragma strict

var maxFallDistance = -10;

function Update ()
{
	if (transform.position.y <= maxFallDistance)
	{
		Application.LoadLevel("Level 1");
		 
	}
}

Just reset it in your fall down script:

if (transform.position.y <= maxFallDistance)
{
    GameMaster.currentScore = 0;
    Application.LoadLevel("Level 1");
}

You will need to import your coin script into your fall down script like so:

#pragma strict
var script1 : CoinScript's Name
var maxFallDistance = -10;
 
function Update ()
{
    if (transform.position.y <= maxFallDistance)
    {
       script1.CoinValue = 0; 
       Application.LoadLevel("Level 1");
 
    }
}

It should be something like this. You might need to change the names of some variables though.

okey i solved the problem.
if (transform.position.y <= maxFallDistance)
{
GameMaster.currentScore = 0;
Application.LoadLevel(“Level 1”);
}

it worked after my second try, dunno why :slight_smile:

hi i am facing problem is that…i want to update my score when player is running…but the code i have written updating score while player is not moving
here is my code…
public class ScoreManager : MonoBehaviour
{

public Text scoreText;
public Text highscoreText;

public float scoreCounter;
public float highscoreCounter;

public float pointPerSecond;
public bool scoreIncreasing;

void Start () 
{
	if (PlayerPrefs.HasKey ("HighScore")) 
	{
		highscoreCounter = PlayerPrefs.GetFloat("HighScore");
	}

}

void Update () 
{
	
	if (scoreIncreasing) 
	{
		//scoreCounter = scoreCounter+=1*Time.deltaTime;
	
		
		scoreCounter += pointPerSecond*Time.deltaTime;
		//scoreCounter += 1 ;
		}


	if (scoreCounter > highscoreCounter) 
	{
		highscoreCounter = scoreCounter; 
		PlayerPrefs.SetFloat("HighScore" ,highscoreCounter);

		//flashingText = FindObjectOfType<Loadingscene>();
		//flashText.gameObject.SetActive (true);
	}
	scoreText.text = "Score :" + Mathf.Round(scoreCounter)	;
	highscoreText.text = "High Score :" + Mathf.Round(highscoreCounter);
}

}