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