- Home /
Character losing life event not firing
Hi, I'm trying to make a script that when my character falls off the side, it means he'll use a life. and while he currently respawns, he doesn't lose a life here's my two parts of code.-
Lives 2 Player.js
private var dead = false;
function OnCollisionEnter(hit : Collision)
{
if(hit.gameObject.tag == "DeadArea")
{
dead = true;
Lives1.LIVES1 -= 3;
}
}
function LateUpdate()
{
if(dead){
transform.position = Vector3(40,16,13);
dead = false;
Debug.Log("Respawned Player 1");
}
else {
Debug.Log("Alive");
}
}
Lives1.js
var Health1 : Texture2D;
var Health2 : Texture2D;
var Health3 : Texture2D;
static var LIVES1 = 3;
function Update ()
{
switch(LIVES1)
{
case 3:
Debug.Log ("1 life lost");
guiTexture.texture = Health3;
break;
case 2:
guiTexture.texture = Health2;
break;
case 1:
guiTexture.texture = Health1;
break;
case 0:
//Application.LoadLevel(0);
break;
}
}
Answer by hijinxbassist · Mar 07, 2012 at 12:16 PM
looks like it should be Lives1.LIVES1 -= 1; (as you want 1 life-point to be removed). Also you are starting on case 3, so the debug should be firing all the time until you actually lose a life(currently looks like the level reloads since you remove 3 points from 3 LIVES1).
something like
static var LIVES1 = 4;
function Update()
{
switch(LIVES1)
{
case 4:
Debug.Log ("No lives lost");
break;
case 3:
Debug.Log ("1 life lost");
guiTexture.texture = Health3;
break;
case 2:
Debug.Log ("2 lives lost");
guiTexture.texture = Health2;
break;
case 1:
Debug.Log ("3 lives lost");
guiTexture.texture = Health1;
break;
case 0:
Debug.Log ("4th life lost/DEAD");
//Application.LoadLevel(0);
break;
}
}
You need 1 case for each life, adding the additional for no lives lost(default case), total of 5 cases with your current setup of 4 lives.
Your answer
Follow this Question
Related Questions
How do I kill off my player, reduce his lives and respawn him? 3 Answers
Player death/ game over c# 1 Answer
Fade on death! 1 Answer
C# Help - Respawn or Reset 1 Answer
How to add Player health and ability to take damage from a cube? 2 Answers