How do I make it so that my bullet projectile for my gun does damage?

Hi, I am new to both Unity and C#. I used a 2 part tutorial to make a gun script, if needed the channel name is “Dave // Game Development.”
The tutorial’s first episode has a projectile bullet-type script that was exactly what I needed for my game, however, I do not know how to make it so that the bullet actually does damage. I do have a damage script from Brackey’s gun tutorial, however, it only works with Raycast shooting scripts, and in this projectile bullet script, Raycasts are not used to deal damage.
The thing I need help with making it so that on collision, the bullet either damages a target if it hits a target and destroys itself right after or just destroys itself if it does not hit a target. I do not have any script for the bullet, but if I need to make the script for damaging on collisions on the bullet prefab itself, please let me know, Any help is appreciated! Let me know if you need any clarification.
Here is the code:

using UnityEngine;
using TMPro;

public class ProjectileGunScript : MonoBehaviour
{
    //bullet 
    public GameObject bullet;

    //bullet force
    public float shootForce, upwardForce;

    //Gun stats
    public int damage;
    public float timeBetweenShooting, spread, reloadTime, timeBetweenShots;
    public int magazineSize, bulletsPerTap;
    public bool allowButtonHold;

    int bulletsLeft, bulletsShot;

    //Recoil
    public Rigidbody playerRb;
    public float recoilForce;

    //bools
    bool shooting, readyToShoot, reloading;

    //Reference
    public Camera fpsCam;
    public Transform attackPoint;
    public LayerMask whatIsEnemy;

    //Graphics
    public GameObject muzzleFlash;
    public TextMeshProUGUI ammunitionDisplay;

    //bug fixing :D
    public bool allowInvoke = true;

    private void Awake()
    {
        //make sure magazine is full
        bulletsLeft = magazineSize;
        readyToShoot = true;
    }

    private void Update()
    {
        MyInput();

        //Set ammo display, if it exists :D
        if (ammunitionDisplay != null)
            ammunitionDisplay.SetText(bulletsLeft / bulletsPerTap + " / " + magazineSize / bulletsPerTap);
    }
    private void MyInput()
    {
        //Check if allowed to hold down button and take corresponding input
        if (allowButtonHold) shooting = Input.GetKey(KeyCode.Mouse0);
        else shooting = Input.GetKeyDown(KeyCode.Mouse0);

        //Reloading 
        if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading) Reload();
        //Reload automatically when trying to shoot without ammo
        if (readyToShoot && shooting && !reloading && bulletsLeft <= 0) Reload();

        //Shooting
        if (readyToShoot && shooting && !reloading && bulletsLeft > 0)
        {
            //Set bullets shot to 0
            bulletsShot = 0;

            Shoot();
        }
    }

    private void Shoot()
    {
        readyToShoot = false;

        //Find the exact hit position using a raycast
        Ray ray = fpsCam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)); //Just a ray through the middle of your current view
        RaycastHit hit;

        //check if ray hits something
        Vector3 targetPoint;
        if (Physics.Raycast(ray, out hit))
            targetPoint = hit.point;
        else
            targetPoint = ray.GetPoint(75); //Just a point far away from the player

        //Calculate direction from attackPoint to targetPoint
        Vector3 directionWithoutSpread = targetPoint - attackPoint.position;

        //Calculate spread
        float x = Random.Range(-spread, spread);
        float y = Random.Range(-spread, spread);

        //Calculate new direction with spread
        Vector3 directionWithSpread = directionWithoutSpread + new Vector3(x, y, 0); //Just add spread to last direction

        //Instantiate bullet/projectile
        GameObject currentBullet = Instantiate(bullet, attackPoint.position, Quaternion.identity); //store instantiated bullet in currentBullet
        //Rotate bullet to shoot direction
        currentBullet.transform.forward = directionWithSpread.normalized;

        //Add forces to bullet
        currentBullet.GetComponent<Rigidbody>().AddForce(directionWithSpread.normalized * shootForce, ForceMode.Impulse);
        currentBullet.GetComponent<Rigidbody>().AddForce(fpsCam.transform.up * upwardForce, ForceMode.Impulse);

        //Instantiate muzzle flash, if you have one
        if (muzzleFlash != null) 
            Instantiate(muzzleFlash, attackPoint.position, Quaternion.identity);

        bulletsLeft--;
        bulletsShot++;

        //Invoke resetShot function (if not already invoked), with your timeBetweenShooting
        if (allowInvoke)
        {
            Invoke("ResetShot", timeBetweenShooting);
            allowInvoke = false;

            //Add recoil to player (should only be called once)
            playerRb.AddForce(-directionWithSpread.normalized * recoilForce, ForceMode.Impulse);
        }

        //if more than one bulletsPerTap make sure to repeat shoot function
        if (bulletsShot < bulletsPerTap && bulletsLeft > 0)
            Invoke("Shoot", timeBetweenShots);
    }
    private void ResetShot()
    {
        //Allow shooting and invoking again
        readyToShoot = true;
        allowInvoke = true;
    }


    private void Reload()
    {
       reloading = true;
        Invoke("ReloadFinished", reloadTime); //Invoke ReloadFinished function with your reloadTime as delay
    }
    private void ReloadFinished()
    {
        //Fill magazine
       // bulletsLeft = magazineSize;
      //  reloading = false;
    }
}

If I have understood correctly, I think what I would do in this case is the following: First make sure that the target and the bullet prefab both have a collider component, and at least one of them has checked “Is Trigger”. Doing this will allow you to use the OnTriggerEnter() functions, which will fire when a collision is detected between two objects. Also, add a script to the target if you haven’t already done so that you can use later to take damage from a bullet if a collision occurs.

I would also add a tag to the Target gameobject, for example “Target” is fine. You can add tags to gameobjects by selecting them, looking in the inspector and then select Tag just under the name of the gameobject. There you can make new tags. This is just so that it will be easier to find references to the Target later via code.

Then what I would do is add a script to the bullet prefab that would look something like this:

public class Bullet : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        // Check if collision is target via tag - needs target gameObjects to be tagged properly
        if (other.CompareTag("Target"))
        {
            // Target has been hit - use script on target to deal damage to it
            float dmg = 10;
            other.GetComponent<NameOfTargetScriptHere>().TakeDamage(dmg);
            // Damage has been dealt, can destroy self now
            Destroy(gameObject);
        }
        else
        {
            // If we did collide, but it was something other than a target - destroy self
            Destroy(gameObject);
        }
    }
}

And the Target script could just be something like this:

public class Target : MonoBehaviour
{
    private float health = 50;
    public void TakeDamage(float dmg)
    {
        health = health - dmg;
    }
}

I think that should work, let me know if it doesn’t work for some reason.