Health Code Not Working right.

I have a health code for my players GUI, and Its not working right when ever i want to add another line it doesn’t run it.
PLEASE HELP!

var levelToLoad : String;
var heart1 : Texture2D; //One live left
var heart2 : Texture2D; //Two lives left
var heart3 : Texture2D; //Full health
//var LIVE = LIVES;

static var LIVES = 3;

function Update () 
{
	switch(LIVES)
	{
		case 3:
			guiTexture.texture = heart1;
		break;
		
		case 2:
			guiTexture.texture = heart3;//IGNORE ME
		break;
		
		case 1:
			guiTexture.texture = heart2;
		break;
		
		case 0:
			guiTexture.texture = heart3;
			LIVES = 4;
		break;
		 	
		case 4:
			Application.LoadLevel(levelToLoad);
			LIVES = 3;
		break; 	 
	}
}

Firstly, i don’t know exactly what you are trying to do there, but let me show you how you can accomplish this logic you wrote with few lines of code.

Obs.: The code below is written in C#, not JS.

public string levelToLoad;
public Texture2D[] hearts = new Texture2D[3];
public int lives = 3;

void Update()
{
    guiTexture.texture = hearts[lives];
    if (lives == 0)
        Application.LoadLevel(levelToLoad);
}

Considering that you’ll set the Textures in the right sequence inside the Editor and that you are substracting LIVES from anywhere, it will work.

Edit: You don’t need to set lives back to 3 as you did after loading the level.

I WAS going through the code and i saw that i had to remove the cross-hair part and capitalize three letters! here is the finished Key script just in case the other ones are fine.

var Length : float = 3;
 
static var HaveKey : boolean = false;
var ShowText : boolean = false;
 
var Text : String = "You picked up a key";

var FirstPersonController = GameObject;

//var Crosshair = FirstPersonController;
 
var other : GameObject;

var CanChange : boolean = false;
 
function Update () {
 
var hit : RaycastHit;
       
var ray : Ray = camera.ViewportPointToRay (Vector3(0.5,0.5,0));
       
var fwd = transform.TransformDirection (Vector3.forward);
 
Debug.DrawRay(transform.position, fwd * Length, Color.green);
       
        if(Physics.Raycast(ray, hit, Length))
 
        {      
               
                hitObject = hit.collider.gameObject;
               
                if(hitObject.gameObject.tag == "Key")
 
                        {
               
                                other.GetComponent(CrossHair).TextureChange();
               
                                if(Input.GetKeyUp(KeyCode.E))
                                {
                       
                                        GetKey();
                                        Destroy(hitObject);
                                       
                       
                                }
                               
                               
                        }
               
                        else if(hitObject.gameObject.tag == "Untagged")
               
                        {
                                other.GetComponent(CrossHair).BackToNormal();
                        }
 
                }
       
        else if(!Physics.Raycast(transform.position, transform.forward, hit, Length))
        {
                other.GetComponent(CrossHair).BackToNormal();
        }
       
       
 
}
 
function GetKey(){
 
        HaveKey = true;
 
        ShowText = true;
       
        yield WaitForSeconds(3);
       
        ShowText = false;
}
 
function OnGUI(){
 
if(ShowText) 
{
        GUI.Label(Rect(Screen.width /2 -62.5, Screen.height /2 + 50, 200, 100), Text);
}
 
}