My boolean doesen't active no matter what!

I have created a script that makes it so that if an enemy touches me, I take damage. But for some strange reason it just don’t feel like activating. If I press the takeDamage button manually it works like it should. I have no idea what i did wrong, help!

public var health : float = 10f;
var takeDamage : boolean;

function OnTriggerEnter (other : Collider){
 if (other.tag == "Enemy") {
 takeDamage = true;
 }
}

function OnTriggerExit (other: Collider){
 if (other.tag == "Enemy"){
 takeDamage = false;
 }
}
 
function Update(){
 if (takeDamage){
 health --;
 }
 
 if (health <0){
 Destroy(gameObject);
 }
}

Try adding some Debug.Log statements in there to see if you’re actually getting to the code:

function OnTriggerEnter (other : Collider){
  if (other.tag == "Enemy") {
    takeDamage = true;
    Debug.Log("In OnTriggerEnter, takeDamage = "+takeDamage);
  }
}

This can at least give you an idea if the variable is being set correctly

Here’s your problem try making these modifications and also add a rigidbody component on your player:

function OnTriggerEnter (other : Collider){
     if (other.gameObject.tag == "Enemy") {
     takeDamage = true;
     }
    }
 
function OnTriggerExit (other: Collider){
 if (other.gameObject.tag == "Enemy"){
 takeDamage = false;
 }
}