I’m building a space shooter (i know, but it’s my first ever game). I have an asteroid in my game that when it is hit by a bullet and explodes, it leaves behind a shield ‘token’ that the player can collect and it activates their shield. The problem is, my ship has two guns, which fire simultaneously, so if the player hits the asteroid with both bullets, 2 instances of the shield token are instantiated.
Is there any way to restrict this so that only one shield ‘token’ is instantiated? I tried a boolean flag with an IF statement but it didn’t seem to work, I also tried turning the bullet collider off once the bullet hits the asteroid, anyone have any ideas?
my code:
//script for bullet
var explosion :Transform;
var shieldBut :Transform;
if(other.gameObject.tag == "asteroidShield")
{
//create impact explosion
Instantiate(explosion, transform.position, transform.rotation);
audio.PlayClipAtPoint(fxExplosion,transform.position);
Destroy(gameObject);
//instantiate shield 'token'
Instantiate(shieldBut, transform.position, transform.rotation);
}
Any help would be greatly appreciated.