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");
          
     }
 }
 
              Answer by kat0r · Jan 19, 2014 at 03:23 PM
Just reset it in your fall down script:
 if (transform.position.y <= maxFallDistance)
 {
     GameMaster.currentScore = 0;
     Application.LoadLevel("Level 1");
 }
 
              sorry but it doesn't work. ball is not working if i use this script.
Answer by BZS · Jan 19, 2014 at 03:48 PM
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.
what do you mean by var script1 : CoinScript's Name ? what should i write ??
Answer by Oguzzhan · Jan 19, 2014 at 06:01 PM
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 :)
Answer by tarun9689 · Mar 31, 2016 at 04:10 PM
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);
 }
 
               }
Your answer
 
             Follow this Question
Related Questions
Does GUI update every time a scene is loaded? 1 Answer
How can i Reset Health,Score,Time??? 0 Answers
Resetting Power up bar 0 Answers
How to instantiate (MonoBehaviour) script multiple times and call void? 1 Answer
Android GUI Button crash 1 Answer