I am making a StarFox like game. In the game meteors are hurtling towards the characters ship, if the ship collides with a meteor the ships current health decrease. However, when I shoot the ships gun the bullets also collide and hurt the ship causing it to destroy itself.
How can I make the ship invulnerable to the bullets but still take damage from the meteors?
Here is my code if it helps at all…this method is in a script for the ships attributes which declares the ships health and the amount of damage the ship takes from a collision.
void OnCollisionEnter()
{
// Decreases our current health when hit by an object
currentHealth = currentHealth - standardHit; //standardHit declares damage taken by collision
// Tests if current health is less than 25
if(currentHealth < 25)
{
// Writes to our debug log
Debug.Log ("Your health is low!");
}
// Tests if current health is less than or equal to 0
if(currentHealth <= 0)
{
// Destroys our game object
Destroy(gameObject);
}
}