- Home /
My Enemy Damage Script not working
I've read many tutorials and tried different things but it's not quite working out for me. My enemy has a rigidbody and a box collider, my bullet prefab also has a rigidbody and the circle collider is set on trigger. Not to mention my bullets go right through my enemy =/
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public float health = 10f;
public float damageAmount = 10f;
Animator anim;
// Use this for initialization
void Awake () {
anim = GetComponent <Animator> ();
}
// Update is called once per frame
void OnCollisionEnter2D (Collision2D col) {
if (col.gameObject.tag == "Bullet") {
TakeDamage (col.transform);
} else {
// Find all of the colliders on the gameobject and set them all to be triggers.
Collider2D[] cols = GetComponents<Collider2D> ();
foreach (Collider2D c in cols) {
c.isTrigger = true;
}
{
anim.SetTrigger ("EnemyDeath");
}
}
}
void TakeDamage (Transform Enemy)
{
health -= damageAmount;
}
}
Comment
Best Answer
Answer by Zhorky · Mar 26, 2015 at 05:07 PM
Is everything set the right way in Edit->Project Settings->Physics 2D?
Your answer
Follow this Question
Related Questions
(C#) Enemy health and take damage from bullets 1 Answer
(C#) My enemy dosent take damage ScriptFix 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I apply damage to the enemy ai with projectile 0 Answers