- Home /
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);
}
}
Answer by JAKKL_Larry · May 07, 2013 at 09:58 PM
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
Answer by Eugenius · May 08, 2013 at 12:21 AM
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;
}
}
Your answer
Follow this Question
Related Questions
Unity is not activating 0 Answers
Simple C# problem 2 Answers
Unity 5.3.3f1 Stuck on "Updating License" - from behind authenicated proxy 0 Answers
GameObject[] Issues 1 Answer
How do I inherit certain varibles and functions from another script. 1 Answer