Kill Enemy when shot 4 times

How do I kill an enemy in Unity. I want to shoot a torrent 4 times before it is destroyed. Here is my code for the prefab playshot and I have it attached to my player.

var projectile : Rigidbody; var range = 100.0; var speed = 20; function Update () { if (Input.GetButtonDown ("Fire1")) { var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation); instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0,0,speed)); Physics.IgnoreCollision(instantiatedProjectile.col lider, transform.root.collider); } }

What type of code do I attach to the enemy?

code for the enemy turrent.

var LookAtTarget:Transform; var damp = 4.0; var bulletPrefab:Transform; var savedTime=0;

function Update () { if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);

transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);

var seconds : int = Time.time; var oddeven = (seconds % 2);

if(oddeven) { Shoot(seconds); } } } function Shoot(seconds) { if(seconds!=savedTime) { var bullet = Instantiate(bulletPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity); bullet.rigidbody.AddForce(transform.forward * 3000); savedTime=seconds; } }

var projectile : Rigidbody;
var range = 100.0;
var speed = 20;
function Update ()
{
    if ( Input.GetButtonDown ( "Fire1" ) )
    {
        var instantiatedProjectile : Rigidbody = Instantiate ( projectile, transform.position, transform.rotation );
        instantiatedProjectile.velocity = transform.TransformDirection ( Vector3 ( 0, 0, speed ) );

        Physics.IgnoreCollision ( instantiatedProjectile.col lider, transform.root.collider );
    }
}

var LookAtTarget: Transform;

var damp = 4.0;

var bulletPrefab: Transform;

var savedTime = 0;

function Update ()
{
    if ( LookAtTarget )
    {
        var rotate = Quaternion.LookRotation ( LookAtTarget.position - transform.position );

        transform.rotation = Quaternion.Slerp ( transform.rotation, rotate, Time.deltaTime * damp );

        var seconds : int = Time.time;

        var oddeven = ( seconds % 2 );

        if ( oddeven )
        {
            Shoot ( seconds );

        }
    }
}

function Shoot ( seconds )
{
    if ( seconds != savedTime )
    {
        var bullet = Instantiate ( bulletPrefab, transform.Find ( "spawnPoint" ).transform.position, Quaternion.identity );

        bullet.rigidbody.AddForce ( transform.forward * 3000 ); savedTime = seconds;
    }
}

Formatted...

My solution:

Make a script on the enemy, have it so that it has a timesHit var.

Have the same script find the bullets (Whether through tags or by names),.

Check the distance between the bullets and the enemy.

Then, If it hits, make timesHit--, and then if timesHit == 0, than Destroy(gameObject);... Just my preference...

//On enemy
var timesHit = 0;

var bullets = FindGameObjectsWithTag ( "bullet" );

for ( var i = 0 ; i < bullets.length ; i++ )
{
    distance = *PSUEDO CODE: bullets _to Enemy ( IF MULTIPLE ENEMIES, MAKE IT AN ARRAY ) *;_
 *if ( distance <= 1 )*
 *{*
 *timesHit++*
 *}*
 *if ( timesHit >= 4 )*
 *{*
 *Destroy ( GameObject );*
 *}*
*}*
*```*

//On enemy var timesHit = 0;

var bullets = GameObject.FindGameObjectsWithTag ( "bullet" );

for ( var i = 0 ; i < bullets.length ; i++ ) { distance = bullets[];

if ( distance <= 1 )
{
    timesHit++;
}

if ( timesHit >= 4 )
{
    Destroy ( GameObject );
}

}

This the error message I am getting, Assets/Standard Assets/Scripts/EnemyHits.js(9,23): UCE0001: ';' expected. Insert a semicolon at the end.

var life = 0;

function OnCollisionEnter(boom : Collision) {

if(boom.gameObject.tag == "bullet")
{

        life +=1;
        if(life == **5**)
        {

            Destroy(gameObject);

        }

}

}

just paste this code to your enemy, change the value of highlighted number in IF statement depends on you how many shot you want to destroy it.