- Home /
OnParticleCollision() problem
hi, im trying to make this space shooting game similar to asteroids. im trying to make a powerup that whatever this particle hits an enemy, it will sendmessage() a function that destroys the enemy end decrements the enemy count. the code works, but the problem is, when more than one particle hits the enemy, it sendmessage() a lot of times therefore ruining the enemy count. for example i have 3 enemies spawned in the map. i used that powerup. the plan is if i used that powerup it will destroy the enemy and decrements 3 times on the enemy count, but what's happening is that each enemy collides more than one particle therefore it sendmessage() a lot of times. how can i tell the code that a particle has already collided with it, so it doesn't need to sendmessage a lot of times?
heres the OnParticleCollision() code:
var collidecount : int = 0; function OnParticleCollision (other : GameObject) {
if (other.gameObject.tag.Equals("Enemy"))
{
print(collidecount);
//other.gameObject.SendMessage("EnemyExplosion"); } }
i used the collidecount variable to hount how many particles was hitting the enemy, and it turns out, it's over a hundred o.o
Answer by JonathanGeoCox · Aug 22, 2012 at 04:09 PM
Add a bool to the enemy that is set to true when the first collision occurs, and is checked before decrementing the enemy count.