Hello,
I am trying to reset my variables when the player loses or wins, and he hits ‘new game’ Right now, just to test the code, I created a function called ‘reset’ which resets three variables (lives, bombs, score) to zero (for the purposes of testing). I put this code in the gamecontroller object. Which I placed in my menu scene.
I call this function when the player hits ‘new game’ on the menu screen. I also have a gameController object in the level that I load. I also update the GUI via script. The Reset function doesn’t seem to work. Instead, it’s pulling the variables directly from the GmeController script’s Awake function, and not resetting them.
What am I doing wrong? Should I only have one game controller throughout my entire game? Is calling Reset before a Scene Load function the wrong way to go about it?
Game Controller Script
static var GameOver : boolean;
var Player : GameObject;
//set the player score
var score : int;
var lives : int;
var bombs : int;
//GUI Variables:
var scoreText : UILabel;
var livesText : UILabel;
var bombText : UILabel;
var gameController:GameController;
//var PowerUpSound: GameObject;
function Awake(){
lives= 1;
bombs = 1;
GameOver = false;
totalEnemies = 1 ;
isWin = false;
crabturret = 1;
DontDestroyOnLoad(this);
UpdateHUD();
}
function Update(){
//print(lives);
}
function Respawn(){
yield WaitForSeconds(.1);
Instantiate(Player, Vector3(-18.0759, 0, -1.6689), Quaternion.Euler(-90, -180,0));
}
// Ui stuff
function UpdateHUD()
{
livesText.text = "Lives: " + lives;
scoreText.text = "Score: "+ score;
bombText.text = "Bombs: "+ bombs;
}
//strt the game over
function Reset(){
lives= 0;
bombs = 0;
score = 100;
GameOver = false;
}