health system script problem?!

Hi guys,

I have been working on a game on iphone and one of scene has a health system which player has three chance to do the right action before showing an on screen gui and moving to a checkpoint.

The problem is when I go to the checkpoint and then move to the previous scene again, the scene is frozen, which turns into a still picture. The odd thing was when I remove the health gui (health system script attached), the other functions in the scene actually worked!! So I am sure the problem is my health system script, but I can’t find the reason why!! Please help me!!

Here is the script,

var health1 : Texture;
var health2 : Texture;
var health3 : Texture;

private var myGUITexture : GUITexture;
private var loser : GameObject;
myGUITexture = GetComponent(GUITexture);



function Start () {
    loser = GameObject.Find("lose");
    loser.active = false;
}



static var LIVES = 3;


function Update () 
{
	switch(LIVES)
	{
	case 3:
		myGUITexture.texture = health3;
		break;
	case 2:
		myGUITexture.texture = health2;
		break;
	case 1:
		myGUITexture.texture = health1;
		break;
	case 0:
		GameObject.Find("health").active = false;
		loser.active = true;		
		break;
	}

}

bump!!

Anybody??

nobody knows what is going on? Just to update my question, I finally get other pieces to work when I visit the same scene at the second time. However, the health system still doesn’t work…

I really can’t find the reason why the script could work at first and lose the function when I revisit.

the only strange thing that I can see is this:

myGUITexture = GetComponent(GUITexture);

it should be assigned inside the start function

Thank you for the reply. I adjusted the script with your suggestion, but it still doesn’t fix the problem…

Okay problem updated again,

I tried to change a few things and tested where the real problem is…
Just found out that every time when I revisit the scene, my input from the the other script is unable to cause the LIVES function to switch images.

Here is the script attached to the other object.

var hit : RaycastHit;


function Update () {
	
	// Use Raycast to pick objects that have mesh colliders attached.
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		    
	
	if (Input.GetMouseButtonDown (0))  //Returns true during the frame the user touches the object
	{
		if (Physics.Raycast (ray, hit, 100)) 
		{
			
			HealthControl1.LIVES -= 1;
		}
		}
}

This works at first time to cause the HealthControl1 script to switch LIVES, but failed to do so when revisiting.

Anybody knows why? Thank you

Yeah you made LIVES a static variable meaning even if you reload the map it will still keep the same value.

So try adding this.

function Start () {
    loser = GameObject.Find("lose");
    loser.active = false;

//NEW CODE
LIVES = 3;
}

Oh, that is why!! It works! Thanks!!!