More than one shot

Hello, I’m creating a 2d game in c#. I found a way to kill my enemies but I want some enemies especially the boss to die after so many shots instead of one shot.

public class Enemy : MonoBehaviour {

public float minSpeed;
public float maxSpeed;

public float currentSpeed;
private float x, y, z;


// Use this for initialization
void Start () {	
	SetPositionAndSpeed();

}

// Update is called once per frame
void Update () {
	
	float amntToMove = currentSpeed* Time.deltaTime;
	transform.Translate(Vector3.down * amntToMove);
	
	if(transform.position.y <= -5f)
	{
		SetPositionAndSpeed();
	}
}

public void SetPositionAndSpeed()
{
	currentSpeed = Random.Range(minSpeed, maxSpeed);
	y = 7.0f;
	z = 0.0f;
	x = Random.Range(-6f, 6f);
	transform.position = new Vector3(x, y,z);		
}

}

public class Projectile : MonoBehaviour {
public float projectileSpeed;
public GameObject ExplosionPrefab;

private Transform myTransform;

// Use this for initialization
void Start () {
	myTransform = transform;

}

// Update is called once per frame
void Update () {
	float amntSpeed = projectileSpeed * Time.deltaTime;
	myTransform.Translate(Vector3.up * amntSpeed);
	
	if(myTransform.position.y >= 8f)
	Destroy(this.gameObject);
	}

void OnTriggerEnter(Collider otherObject) {
	
	if(otherObject.tag == "enemy")
	{
		Enemy enemy = (Enemy)otherObject.gameObject.GetComponent ("Enemy");
		//Explosion prefab. where it should explode
		Instantiate(ExplosionPrefab, enemy.transform.position, enemy.transform.rotation);
		//random positions and speed
		enemy.SetPositionAndSpeed();
		
	Destroy(gameObject);
	}
}

}

Those are my two scripts for killing the enemy.

Firstly in your enemy script you need to add a health variable in there and when the projectile hits your enemy, reduce the health completly to zero. So for example your enemy may have health of 15 and when the projectile hits the enemy health is reduced by 15.

For your boss gameobject (which I assume you have) re-tag it as “boss” and in your OnTriggerEnter() function check that the tag is “boss”, similar to how you checked for enemy, and reduce the health by 5 thus the boss will need 3 shots to die.

// at the top of your enemy script
public int health = 15;

// in your projectile script
void OnTriggerEnter(Collider otherObject)
{
    if (otherObject.tag == "enemy")
    {
        Enemy enemy = (Enemy)otherObject.gameObject.GetComponent("Enemy");
        enemy.health -= 15;
        if (enemy.health <= 0)
        {
            Instantiate(ExplosionPrefab, enemy.transform.position, enemy.transform.rotation);
            enemy.SetPositionAndSpeed();
            Destroy(gameObject);
        }

    if(otherObject.tag == "boss")
    {
        // same as above
        enemy.health -= 5;
        // rest of the code here
    }
}