why doesn't GetButtonDown work in my script?

I am following along with yet another tutorial trying to learn to code in unity and up intill now all the many problems i have had i have been able to solve or search for the solution intill now, im trying to make it so that when i get close to an enemy and click the left mouse his life goes down, when the kid in the tutorial plays the code it works but not for me, i have set the enemy’s collier box so its bigger than the object and the trigger works but when i click the mouse it don’t take health. here is the code;

var Health = 3;

var TakeDamage : boolean;

function OnTriggerEnter ( other : Collider ){

if (other.tag == "Player"){

TakeDamage = true;
}

}

function OnTriggerExit ( other : Collider ){

if (other.tag == "Player"){

TakeDamage = false;
}

}

function update (){

if (TakeDamage){
	
	if (Input.GetButtonDown("Fire1")){
	
	Health --;
	}

}

}

any help would be great.

Use the code snippet “Debug.Log(TakeDamage);” at the very beginning of the update() function. Then when you run your game/application you can see in the Console window, if the TakeDamage boolean is true or false.

If it is false, then you need to check so the OnTriggerEnter()-function is working as you want it to work. Most likely is the “other.tag” variable not equal to “Player”.

function Update() is the correct synthax.