GUI not counting Player Deaths

There is something going on with my player or enemy script code. After I die, many functions are not useable. The first I noticed was a powerup that works when the player comes in contact with an enemy. It will work until the player dies. Then it and other functions stop working.

Now that I’m working on my GUI, I’m noticing that it isn’t counting the number of times the player is dying. (side note, not sure if I want to count the number of times the player dies, or count it down from a set amount until getting a game over.) Note: it counts the first death, but then nothing afterwards, no matter how many different ways I try to kill the player.

I have a counter used for counting coins, and regardless of whether or not the player dies, the tally for that works as expected because it has nothing to do with my enemy and playerscript. Clearly something is wrong with how the player dies, right?

My skype is: Tekksin

The part of my enemy script involving this issue reads:

private var done = false;

function OnTriggerEnter(other : Collider){
if(!stomp){	
		if(other.tag == "Player"){
			if(player.Diamond == true){
					coin = Instantiate(thePrefab, transform.position, Quaternion.identity);
					Destroy(gameObject);
				}
				else if(player.Pick == true && player.Diamond == false){
					player.Pick = false;
					return;
				}
				else {
					var Player : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
					Destroy(other.gameObject);
					if(!done){
						Lives.lifeTotal =- 1;
						done = true;
					}
			}
		}
	}
}

There isn’t a relevant part of my “player script” that I see could interfere with this. The respawning function isn’t on it, so here is my respawn script:

private var done = false;
var Player : GameObject;
var spawnPoint : Transform;

function OnTriggerEnter(other : Collider) {
	if(other.tag == "Player"){
		Destroy(other.gameObject);
		var Player : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
		if(!done){
			Lives.lifeTotal =- 1;
			done = true;
		}	
	}
}

here is my GUI script:

static var lifeTotal = 0;

function OnGUI (){
	guiText.text = "Lives: " + lifeTotal;
}

I hope I’m not missing some info. What the hell am I doing wrong??

One problem I can see, but there could be more since you shared so little of your code, you didn’t even share the declaration of variables (what is Player for example?):

var Player : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);

The temporary variable that you define uses the same name as the prefab.
Try:

var newPlayer : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);

Where Player is a prefab, and you do not make any modifications to it. If you want to store a reference for the instance of the player, store it in a separate variable than the prefab, because you will need the prefab reference to instantiate new players.

Your respawn script says:

private var done = false;

//...

if(!done){
    Lives.lifeTotal =- 1;
    done = true;
} 
  • Firstly “Lives.lifeTotal =- 1” will assign -1 to lifeTotal, do you mean “Lives.lifeTotal -= 1” which will decrement lifeTotal?
  • Secondly are you resetting done to false elsewhere? If not this code will only execute once.

Edit: I just noticed the exact same code is in your enemy script. Both of these "done"s are private instance variables i.e. they do not share a value. I suggest you consider why they are there and find approach for the problem they are intended to solve.

ok, and now this site isn’t letting me reply anymore, or mark KellyThomas’ response as correct. Only after I figured out my problem did I notice it’s exactly what he said (totally went over my head). I found out when I tried just putting “++” instead of “=-” in that lifeTotal spot.

Anyways, now the forum has problems, for me lol. so random.