so hi Folks, i have a question about game reset.
i implemented a script with counts my life down, and if the lifes equals 0, the main menu appers.
for this i used:
Application.LoadLevel(0);
if i go back in the game with “Play Game” my life is still 0,
so what should i do, to reset the stats after game Over?
thx for any answers ^^
and btw. im new in Unity and Javascript =D
I don’t know how Unity itself handles static variables, but if it is static that maybe why. I’d suggest that in the Start() or Awake() function set life to whatever you normally set it to.
hmm jeah its static, i needed it for the counter.
where i have to set the Start() or Awake() function?
my Life Counter is inside of my controller script at the respawn (i modified the 2d platformer script) and inside my pickup script.
// Check our life
static var LIVES = 3;
function OnDeath () {
LIVES --;
if(LIVES < 1){
Application.LoadLevel(0);
}else{
Spawn ();
}
}
and here
function ApplyPickup (player : Controller) {
if (pickupType == PickupType.Gem) {
Count ++;
//Check our gems and life
if(Count == maxCount){
Controller.LIVES ++;
Count = 0;
}
}
I’m not overly familiar with Javascript in Unity, but I think you can put it anywhere in the same file as the lives variable as long as it is called
function Start()
What it looks like in some examples I’m seeing. But I think if you do
function Start() {
LIVES = 3;
}
it may work.
or you could do it this way… I myself did this.
if (Lives == 0) {
Application.LoadLevel(0);
Lives = 3;
}
i fixed the problem now.
i put it in the awake function in my controller script =D
function Awake () {
movement.direction = transform.TransformDirection (Vector3.forward);
controller = GetComponent (CharacterController);
Spawn ();
LIVES = 3;
GemPickup.Count = 0;
}
but i think when i skip into the next level, it will start with 3 lives or?
Yup.
There are some easy fixes. For example you could do something like the following.
if(Application.loadedLevelName = “Scene1Reset”)
{
LIVES = 3;
}
hey man u don’t need to access that by use static parameter… like when u have several chaacter that all of the have heal…
u can use get component…
like GameObject.Find(“[object name]”)*orFindWithTag(“[object name]”)*.GetComponnent(“[your script name]”).[your parameter name]=[value]