Hello guys,
I have three scenes.the first scene allows player to enter a number. Scene2 checks if the entered number is equal to the mystery number.scene3 is the final for the game, if the entered number is correct.Through the game I want to save number of the attempts of the player. But each time scene1 is reloaded, previous GUI label is getting disappeared from the scene. and the Gui labels for scene2 and scene3 are not recognizable or they dont work.
Here is the code for the three of the scenes: thanks for any answers and advices.
//Scene1
// _count shows the number of attemps of the player to guess the random number(1-9)
static var _count : int;
// enter_number is the number that player enters to guess the random number(1-9)
var enter_number : String;
// dummy returns the string value of enter_number to integer
static var dummy : int;
// randm is the target number to be found
static var randm : int = Random.Range(1,9);
function Awake (){
}
function Start () {
}
function Update () {
}
function OnGUI () {
// GuI allows player to enter a number
enter_number = GUI.TextField ( Rect (0,0,100,25), enter_number, 1);
if (enter_number!="")
{
// parsing to integer
dummy = parseInt(enter_number);
}
if (GUI.Button (Rect(0,20,100,25), "Enter a number"))
{
//player pushes the button to enter the number and scene2 checks if the number is equal to target number.
Application.LoadLevel ("scene2");
}
if (_count!=0)
{
// GUI labels the attempt count of the player did.
GUI.Label(Rect(200, _count*10,100,30), "Number" +_count);
}
}
//Scene2
function Start () {
Debug.Log (script1.dummy);
}
function Update () {
// counting the attempt number
script1._count = script1._count+1;
// checks if the entered number equals
if (script1.dummy == script1.randm)
{
Application.LoadLevel ("scene3");
}
else
{
// allaows player to enter number one more time
GUI.Label(Rect(0,0,100,30), "Number" + script1._count);
Application.LoadLevel ("scene1");
}
}
//scene3 for the final : if the player guesses the correct number
function Start () {
}
function Update () {
GUI.Label (Rect (0,0,100,30), "You found the number");
Debug.Log ("Congrats you found the number " + script1._count + ". try");
}