# Projectile/Enemy Behavior

## Projectile behavior

Now that we know how triggers and tags work, let’s set up the projectile behavior! Create a new script within the Scripts folder called “ProjectileBehavior”. Then drag and drop it in the projectile inspector from the projectile in the Prefabs folder, and open the script up. Remove the Start() and Update() function and replace it with this:

void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag != "")  //destroy projectile if it collides with anything but the player
{
// make the projectile disappear

}
}


In this function, we want to destroy the projectile if it collides with anything but the player. Inside the quotation mark, what do you think we should add? Within the body of the function, what should we put to make the projectile disappear?

## Enemy behavior

Now let’s test by running the game! If we did it correctly, the projectile should disappear upon contact when it touches anything but Nuvi! However, when we fire at the enemy, notice how the projectile disappears, but the enemy does not. To fix this issue, we must create a similar script that revolves around the enemy’s behavior. To do this, create a new script in the Scripts folder called “EnemyBehavior” and attach it to the Alien_pink’s inspector. Similar to how we made the “ProjectileBehavior” script, remove the Start() and Update() function and add this:

void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "") //destroy enemy if it collides with a projectile
{
// make the enemy disappear

}
}


In this function, we want to destroy the enemy if it collides with a projectile. What do you think we should add? What should we put in the body of the function to make the projectile disappear?