- Home /
My bullet script doens't work.
my scripts doesn't seem to be working. Even though I use tags. My bullet is a prefab. I added a collider for my enemy and made it is trigger. I don't know why it doesn't work. also my prefab's tag is bullet too.
{
public float Health = 10;
public float CurrentHealth = 10;
public float MinHealth = 0;
void Start()
{
}
void Update()
{
if (CurrentHealth < 1)
Destroy(gameObject);
}
void OnCollisionEnter(Collision collision)
{
int Damage = 5;
if (collision.gameObject.tag == "bullet")
{
CurrentHealth -= Damage;
}
}
}
Answer by logicandchaos · Jan 25, 2021 at 04:39 PM
in void OnCollisionEnter(Collision collision) add Debug.Log(collision.gameObject.tag); Then you will see if it is colliding. Another issue could be that your bullets are moving too fast that it's missing the collision. You can fix by making collision continuous in the inspector, using raycasts instead or slowing down your bullets.
Your answer
Follow this Question
Related Questions
Bullet subtracting damage from enemy health 1 Answer
How to create/fix fire damage script???? 1 Answer
Health and Damage [C#] 2 Answers
bullet damage problem 1 Answer
My player HP are get decreased from several GameObjects that has is Trigger on 0 Answers