Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 svettgunnar · May 28, 2011 at 05:13 PM · menuscoresystemmain

Main Menu issues when restart

Hey, I'm using a script that allows me to use an Main Menu ingame but I got a problem with it... when I click on restart the scene restarts fine but the score system doesn't... All the score I've earned doesn't restart when the scene does - I still got the score i had when I died. Could anyone take a look and tell me where I done wrong?

This is the ingame main menu script:

 var guiSkin: GUISkin;
 var nativeVerticalResolution = 700.0;
 var isPaused : boolean = false;
 Screen.showCursor = false;
 
 function Update()
 {
     if(Input.GetKeyDown("escape") && !isPaused)
     {
         print("Paused");
         Time.timeScale = 0.0;
         isPaused = true;
         Screen.showCursor = true;
     }
     else if(Input.GetKeyDown("escape") && isPaused)
     {
         print("Unpaused");
         Time.timeScale = 1.0;
         isPaused = false;    
         Screen.showCursor = false;
     } 
 }
 
 function OnGUI ()
 {
     // Set up gui skin
     GUI.skin = guiSkin;
 
     // Our GUI is laid out for a 1920 x 1200 pixel display (16:10 aspect). The next line makes sure it rescales nicely to other resolutions.
     GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1)); 
 
 
     if(isPaused)
     {
       // RenderSettings.fogDensity = 1;
       if(GUI.Button (Rect((Screen.width)/3,540,200,75), "Quit", "button2"))
       {
          print("Quit!");
          Application.Quit();
       }
       if(GUI.Button (Rect((Screen.width)/3,440,270,75), "Restart", "button2"))
       {
          print("Restart");
          Application.LoadLevel("3");
          Time.timeScale = 1.0;
          isPaused = false;
       }
       if(GUI.Button (Rect((Screen.width)/3,340,310,80), "Main Menu", "button2"))
       {
          print("Main Menu");
          Application.LoadLevel("0");
       }
       if(GUI.Button (Rect((Screen.width)/3,240,270,75), "Continue", "button2"))
       {
          print("Continue");
          Time.timeScale = 1.0;
          isPaused = false;
          Screen.showCursor = false;
       }
    } 
 }
 @script AddComponentMenu ("GUI/Pause GUI")


And this is the score system scripts:

 using UnityEngine;
 using System.Collections;
 
 public class ScorePointCounter : MonoBehaviour
 {
     public GUISkin guiSkin = null;
     public static int points = 0;
 
     void OnGUI()
     {
         GUI.skin = guiSkin;
         GUI.Label(new Rect(0.0f, 0.0f, 700.0f, 500.0f), points.ToString());
         GUI.skin = null;
     }
 }

_

 using UnityEngine;
 using System.Collections;
 
 public class Zombie : MonoBehaviour
 {
     public int points = 1; // You can edit this in the inspector
 
     void OnDestroy()
     {
         ScorePointCounter.points += points;
     }
 }
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

1 Reply

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

Answer by Bunny83 · May 28, 2011 at 05:24 PM

Where do you reset your score? The static variable points will not do anything when you load another level. It's static! It isn't bound to any class instance in the scene. I guess you just want to add a Start function to your ScorePointCounter class and set the points to 0.

edit

 using UnityEngine;
 using System.Collections;
 
 public class ScorePointCounter : MonoBehaviour
 {
     public GUISkin guiSkin = null;
     public static int points = 0;
 
     void Start()
     {
         points = 0;
     }
 
     void OnGUI()
     {
         GUI.skin = guiSkin;
         GUI.Label(new Rect(0.0f, 0.0f, 700.0f, 500.0f), points.ToString());
         GUI.skin = null;
     }
 }
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 svettgunnar · May 28, 2011 at 05:35 PM 0
Share

Damnit, tried to edit my script but I just get alot of erroes - could u edit my script, thanks.

avatar image Bunny83 · May 29, 2011 at 03:48 PM 0
Share

:D what's the problem of adding a start function to your script? I've edited my answer to include the full script.

Btw: if you use DontDestroyOnLoad your Start function won't be called if you load a new level. You should use OnLevelWasLoaded ins$$anonymous$$d of Start in this case.

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

2 People are following this question.

avatar image avatar image

Related Questions

Pickup Counter Script 2 Answers

Scoresystem wont function correctly 0 Answers

script to save and load a game 3 Answers

Loading multiple levels error 0 Answers

Main Menu Button Help! 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