Alright I’m totally stuck and I can’t figure it out. I’m trying to make it so that every time I get hit I loose health from the health bar, but every time I get hit nothing happens, I also made a dead zone so if the character falls off you loose one health piece. This is what I have so far tell me what needs fixing if you can, there’s no apparent errors, except maybe a logic error because I must have set something wrong.
First code is the movement and getting hit
Second is the GUI Health script
//Getting Hit Script
//Easy movement on the x-z plane.
var speed = 10.0;
var rotationSpeed = 100.0;
private var dead = false;
//Getting Hit
var tumbleSpeed = 0;
var decreaseTime = 0.01;
var decayTime = 0.01;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
//HealtControl Here
HealthControl.LIVES -= 6;
}
}
function Update () {
// Get the horizontal and vertical axis.
var translation = Input.GetAxis ("Vertical") * speed;
var rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
// Make it move 10 meters per second instead of 10 meters per frame...
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
// Move translation along the objects z-axis
transform.Translate (0, 0, translation);
// Rotate around our y-axis
transform.Rotate (0, rotation, 0);
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0,4,0);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
if(gotHit)
{
if(tumbleSpeed < 1)
{
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
else
{
//were hit spin around character
transform.Rotate(0, tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed-decreaseTime;
decreaseTime += decayTime;
}
}
}
//GUI_Health Script
var health1 : Texture2D; //one live left
var health2 : Texture2D; //two live left
var health3 : Texture2D; //three live left
var health4 : Texture2D; //four live left
var health5 : Texture2D; //five live left
var health6 : Texture2D; //full left
static var LIVES = 1;
function Update ()
{
switch(LIVES)
{
case 6:
guiTexture.texture = health6;
break;
case 5:
guiTexture.texture = health5;
break;
case 4:
guiTexture.texture = health4;
break;
case 3:
guiTexture.texture = health3;
break;
case 2:
guiTexture.texture = health2;
break;
case 1:
guiTexture.texture = health1;
break;
case 0:
//gameover script here
break;
}
}