- Home /
Zombie Damage Parts Problem
Hello everyone so I basically have this problem, which is kinda frustrating. I have created a health system for the enemy (in that case a zombie) and I want it to take damage differently, according to the area I hit it. In this case I want two areas: Head and Body. Problems occur when I try to do this by collision detection it's not even recognizing and separating the body from the head, although they are different meshes. Here is what I managed to do so far. Any help would be amazing!
using UnityEngine;
using System.Collections;
public class EnemyHealthSystem : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public GameObject zombie;
void Awake () {
}
// Update is called once per frame
void Update () {
Death ();
}
void OnCollisionEnter (Collision col)
{
//This is the part that doesn't work. I want it to recognize the
// Object that is colliding on and subtract the number from the
// current health of the enemy.
if (col.gameObject.tag=="head")
{
curHealth -= 100;
Destroy (col.gameObject);
}
else
curHealth -= 20;
Destroy (col.gameObject);
}
void Death()
{
if (curHealth <= 0)
Destroy (zombie);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612041909im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
c# bullet holes appearing on collider 1 Answer
Distribute terrain in zones 3 Answers
Health and Damage [C#] 2 Answers
C# Grenade Explosion in Radius 1 Answer
HOw to make a custom mesh collider 1 Answer