- Home /
handling collision with two objects of the same tag
I have an object set up for collisions using
OnTriggerEnter(Collider other)
{
if (other.tag == "Bullet")
{
health -=10;
}
}
the problem I seem to be encountering is that when two "Bullet"s hit the object at the same time, it doesn't register the hit. maybe im missing something fundamental here?
thanks
Comment
Best Answer
Answer by Em3rgency · Jul 02, 2013 at 06:27 AM
OnTriggerEnter is funky like that. I had a similar problem where I had to do things both during trigger enter and exit, but the functions would often not fire off correctly if I collided with several objects at once.
For some reason, this solved itself when I only used the enter/exit functions to count the collisions, and did my actual code in the update function instead. So try something like this
int unprocessedBullets = 0;
void Update()
{
if(unprocessedBullets > 0)
{
health -= 10;
unprocessedBullets--;
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Bullet")
unprocessedBullets++;
}