Different types of projectiles cause different amounts of damage...

I have an enemy HP script. It functions off the very basic: two int-s, one for current health, and one for maximum health. Now I want to reduce the current health when a specific object with a specific tag collides with it. How can this be achieved? please consider that all my work is in c#.

Thanks in advance!

If your using the Unity physics engine then we can use the ‘OnCollisionEnter’ callback on a script attached to the object that will be colliding with the enemy.

//this is called automatically when two colliders first intersect,
//(one of the colliding objects must have a rigid body)
void OnCollisionEnter(Collision collisionInfo)
{
    if(collisionInfo.gameObject != null && collisionInfo.gameObject.tag == "tagName")
    {
        HealthScript hp = collisionInfo.gameObject.GetComponent<HealthScript>();

        if(hp != null)
        {
            hp.ReduceHealth(/*damage here*/);
        }
    }
}

Or if you’re moving things around yourself without rigid bodies etc, we can use raycasting (this is only really suitable for projectiles):

//replace and update these variables as needed:
Vector3 direction;
float speed;

void Update()
{
    RaycastHit hitInfo;
    Ray ray = new Ray(transform.position, direction.normalized);

    if(Physics.Raycast(ray, out hitInfo, speed))
    {
        if(hitInfo.collider != null && hitInfo.collider.tag == "tagName")
        {
            HealthScript hp = hitInfo.collider.GetComponent<HealthScript>();
            if(hp != null)
            {
                hp.ReduceHealth(/*damage here*/);
            }
        }
    }
}