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 /
avatar image
0
Question by S_Byrnes · Mar 16, 2014 at 10:06 AM · scorepointsshowgameover

How To Show Score On End Game

Hey guys, I need to show score at the end of the game, I want to do this like my pause menu with gui and time.scale codes but the part of my game that handles score has a lot more in it than just score

Essentially I need to make a separate script to handle end game and then use that to call upon the private int score; but only after it's accumulated it's count, I just don't know how to go about it though

here's the part of the script that handles game over:

 if (numberOfLives <= 0)
                 {
                     HideGroup("GAMEOVER", false);
                     AudioSource.PlayClipAtPoint(GameOver, Camera.main.transform.position);
                     respawnTimer = Time.time + gameOverTime;
                 }

and here's the couple of parts that handle score:

 private int score;

 void Start () {
         Screen.sleepTimeout = SleepTimeout.NeverSleep;
         currentLevel = 0;
         numberOfLives = 3;
         score = 0;
         // Game over
         HideGroup("GAMEOVER", true);
         HideGroup("GUI", false);
         respawnTimer = 0;
         bPlayerExistedLastUpdate = true;
     }

This part is at the very bottom:

 public void AddPoints(int points) {
         score+=points;
         Debug.Log("Score: " + score);
     }

and throughout that they get score from destructed objects in other scripts, but the above code is spread out through the one script.

I hope someone can understand what I just said.. Thanks!

Comment
Add comment · Show 2
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 saruul34 · Mar 16, 2014 at 12:25 PM 0
Share

Why don't you make your score static.

    public static int score;

Then you can get your score from another script like this print($$anonymous$$yScript.score);

avatar image S_Byrnes · Mar 16, 2014 at 12:37 PM 0
Share

Hey thanks, that got rid of my errors, but when I lose all lives the GUI window doesn't pop up, here's the game over script after using the static int

 using UnityEngine;
 using System.Collections;
 
 public class Over : $$anonymous$$onoBehaviour {
         
         private bool gameOver = true;
         public GUISkin guiSkin;
         
         Rect windowRect = new Rect (0, 0, 620, 520);
         //private bool toggleTxt = false;
         //string stringToEdit = "Text Label";
         //float hSliderValue = 0.0f;
         //float vSliderValue = 0.0f;
         //private float hSbarValuet;
         //private float vSbarValue;
         //private Vector2 scrollPosition = Vector2.zero;
         
         void  Start (){
             
             Time.timeScale = 0.0f;
         }
         
         void  Update (){
 
             windowRect.x = (Screen.width - windowRect.width) / 2;
             windowRect.y = (Screen.height - windowRect.height) / 2;
                 
         if (GameLogicScript.numberOfLives <= 0)
         {
             Time.timeScale = 0.0f;
             gameOver = true;
         } else {
             gameOver = false;
             Time.timeScale = 1.0f;
                 }
             }
         
         void OnGUI(){
             
             GUI.skin = guiSkin;
             
             if (gameOver){
                 windowRect = GUI.Window (0, windowRect, Over$$anonymous$$enu, "Game Over");
             }
         }
         
         void Over$$anonymous$$enu(int windowOver) {
             
             if (GUI.Button ( new Rect(140,50,340,50), "Restart"))
             Application.LoadLevel("TestScene1");
             if (GUI.Button ( new Rect(140,120,340,50), "$$anonymous$$ain $$anonymous$$enu"))
             Application.LoadLevel ("$$anonymous$$enu");
             GUI.Button ( new Rect(140,190,340,50), "Options");
             GUI.Button ( new Rect(140,260,340,50), "Score: " +GameLogicScript.score);
             if (GUI.Button ( new Rect(140,330,340,50), "Quit"))
                 Application.Quit ();
         }
     }

if you need to see the other script, I will post it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gnemlock · Mar 16, 2014 at 12:39 PM

I would have a GUIText in your scene wherever you want the score displayed, and set it up with a generic score display as the text so you can see it as it will display in your scene.

Whatever object holds your score script ("gameController"), have this code in it

 public GUItext scoreText
 
 void Start()
 {
 scoreText.text=""; //reset your score text to start empty/invisible
 }

Then, when you handle the gameover you would include

 scoreText.text="Final Score: " + score;

Then when you reset your score you would just reset the scoreText.text with it.

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 S_Byrnes · Mar 17, 2014 at 02:32 AM 0
Share

Thanks for this, with some fiddling around with it I was able to use it, but not for what I asked for. I ended up getting the GUI to display correctly but the way I did it made me get rid of my other GUI elements that displayed score while the player was playing, this fixed it.

But now I have a problem of when I have my end game gui pop up, the game will pause (because I'm using timescale) and then the user can push the GUI buttons and either restart, go to main menu or quit. But if the user presses anything but the GUI, the game will reset in the background while the gui is still there.

What I need is to be able to disable the users ability to touch anything but the GUI window & GUI buttons, any ideas?

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

How can i destroy a collider on collision? 2 Answers

Modified Roll a Ball Tutorial,Modified Roll a Ball tutorial question 1 Answer

Show Current Score on GAMEOVER Scene 0 Answers

Highscore Save 0 Answers

OnControllerColliderHit counting twice towards score 0 Answers


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