Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Oguzzhan · Jan 19, 2014 at 02:41 PM · guiscorereset

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");
          
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0

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");
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ivan2532 · Jan 19, 2014 at 04:18 PM 0
Share

That should work as a charm!

avatar image Oguzzhan · Jan 19, 2014 at 05:39 PM 0
Share

sorry but it doesn't work. ball is not working if i use this script.

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Oguzzhan · Jan 19, 2014 at 05:34 PM 0
Share

what do you mean by var script1 : CoinScript's Name ? what should i write ??

avatar image
0

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 :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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);
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges