- Home /
Question by
wooden_sword789 · Aug 14, 2014 at 07:32 PM ·
javascriptcollisionhealth
Why Is My Enemy Health Script Not Working?
var Health = 10;
var DamageTake = 1.0;
function OnCollisionEnter(other : Collision){
if(other.Tag=="Player"){
Health = Health - DamageTake;
}
}
Comment
var Health = 10; var DamageTake = 1.0;
function OnCollisionEnter(other : Collision){ if(other.Tag=="Player"){ Health = Health - DamageTake; } }
Try inserting Debug.Log statements to look at the actual results of your conditional statement.
also you dont have to do health = health - takedamage; you can do health -= takedamage; its shorter
Answer by Nick4 · Aug 15, 2014 at 05:15 AM
Type "collision" is not a game object so it doesn't have a tag property. Use other.gameObject
instead.
function OnCollisionEnter(other : Collision){
if(other.gameObject.tag == "Player"){
Health = Health - DamageTake;
}
}
This will do.
Your answer
Follow this Question
Related Questions
Player take damage on collision with AI 1 Answer
Character controller mess up damage 3 Answers
Problem with health and level reload system 2 Answers
Checking to see if two objects are colliding. 2 Answers
Object Collision PLEASE HELP!!! 1 Answer