- Home /
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;
}
}
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;
}
}
Damnit, tried to edit my script but I just get alot of erroes - could u edit my script, thanks.
: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
Follow this Question
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