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;
}
}