- Home /
Enemy Boss doesn't take damage.
I have a problem with my enemy boss. When I shoot at him I deal no damage to him. When I shoot at my other enemy (not a boss :P) he recieves the damage. On the boss I have attached Rigidbody2D (which is set to Kinematic) a Circle and Box Collider2D(is Trigger off), I have this script attached to the boss:
using UnityEngine;
public class BossHealthTEST : MonoBehaviour { public int health; //<- Type health amount here
public GameObject deathEffect;
public void TakeDamage(int damage)
{
health -= damage;
if (health <= 0)
{
Die();
}
}
void Die()
{
Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
And this is the script for my other enemy that takes the damage when I shoot at him. Honestly Iam a newbie that's why I ask for help with this simple script ... :P
using UnityEngine;
public class Enemy : MonoBehaviour { public int health = 100;
public GameObject deathEffect;
public void TakeDamage (int damage)
{
health -= damage;
if (health <= 0)
{
Die();
}
}
void Die()
{
Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
Quick question @Vandal16 : are you modifying the health inside your inspector before pressing play ?
Yes but earlier I went with "public int health = 100;" and it also did not helped.
It sounds like it is a trigger issue. Is the triggering/collision setup identically on the boss and non-boss?
It is all I can think of. Perhaps share screenshot of RigidBody and Collider setup of both entities?
Where are you calling the TakeDamage()
function from? $$anonymous$$ay we see what's supposed to be triggering the function?
I am searching it in my scripts but i can't find it. $$anonymous$$aybe I've never created that one and that may be the problem ? But it is weird I have the TakeDamage()
function in my other enemy too and it works fine...
Answer by DisuraRandunu · May 14, 2020 at 09:30 AM
I think it's because of the kinematic. There should be a non-kinematic rigidbody for Colliders to work
If you mean by that the "Body type" like Dynamic,Static i tried them all.
Answer by DisuraRandunu · May 13, 2020 at 04:41 PM
@Vandal16 Even if the above answer doesn't help and you have some value in health, then the issue is about the boss being kinematic. Colliders doesn't work in non-kinematic rigidbody i think..
Sadly it doesn't work. I tried also with dynamic,static etc. different settings in the colliders,rigidbody and none helped...