- Home /
I want to make a zombie fps game and the zombie isn't taking damage
I got Unity one day ago and I started to use it today. I wanted to make a zombie fps game as my first game. I need the zombie to walk towards me, deal damage, and take damage. I got all the animation and health bar working, but the zombie isn't taking damage. I tried adding a hitbox object with a collider and a damage script but it isn't working. I know my weapons' are working because I added in another enemy and it was taking damage.
Can anyone help?
My zombie script is below.
void Start()
{
pathfinder = GetComponent<NavMeshAgent>();
target = GameObject.Find("Player").transform;
}
void Update()
{
pathfinder.SetDestination(target.position);
}
My damage script is below.
[Range(0, 1)] [Tooltip("Multiplier to apply to self damage")]
public float SensibilityToSelfdamage = 0.5f;
public Health Health { get; private set; }
void Awake()
{
// find the health component either at the same level, or higher in the hierarchy
Health = GetComponent<Health>();
if (!Health)
{
Health = GetComponentInParent<Health>();
}
}
public void InflictDamage(float damage, bool isExplosionDamage, GameObject damageSource)
{
if (Health)
{
var totalDamage = damage;
// skip the crit multiplier if it's from an explosion
if (!isExplosionDamage)
{
totalDamage *= DamageMultiplier;
}
// potentially reduce damages if inflicted by self
if (Health.gameObject == damageSource)
{
totalDamage *= SensibilityToSelfdamage;
}
// apply the damages
Health.TakeDamage(totalDamage, damageSource);
}
}
}
Does zombie have a health component? In InflictDamage() at top put Debug.Log(Health); Also not sure how it is working but you named your instance the same as your class.. Health Health; should be Health health; Also can you show the Health script? and maybe your inspector of how your enemies are setup.
Your answer
Follow this Question
Related Questions
Need zombie to inflict damage 0 Answers
Damage trigger? 1 Answer
regenerating health 3 Answers
How to make zombie inflict damage 1 Answer
Attack Script problem please help 1 Answer