How do I make bullet holes become children of the object that they hit?

I am making a shooting script that uses ray casts to simulate bullets and I want the bullet holes to move and rotate with the object that was hit (in this case, objects tagged with “wood”). This way the target object can be movable via rigidbody. (the target already has a collider and rigidbody if they need to be referenced).

Here is my shooting code:

 using UnityEngine;

using System.Collections;

public class Full_Auto_Gun_Script : MonoBehaviour
{
//Gun Stats
public float damage;
public float range;
public float heat = 0f;

//Cameras
public Camera fpsCam;

//Bools
public bool isFullAuto;
public bool hasSelector;
public bool isShooting;

//Objects
public ParticleSystem muzzleFlash;
public GameObject muzzleLight;
public ParticleSystem gunSmoke;
public GameObject sandImpactEffect;
public GameObject woodImpactEffect;

void Awake()
{
    heat = 0;
}

// Update is called once per frame
void Update()
{
    if (heat >= 0)
    {
        gunSmoke.Stop();
    }

    if (heat > 0 && !isShooting)
    {
        gunSmoke.Play();
    }

    if (!Input.GetKey(KeyCode.Mouse0))
    {
        isShooting = false;
    }

    if (heat > 0f && !isFullAuto)
    {
        heat = heat - 0.04f;
    }
    if (heat > 0f && isFullAuto && !isShooting)
    {
        heat = heat - 0.25f;
    }

    
    if (heat < 0f)
    {
        heat = 0f;
    }

    muzzleLight.SetActive(false);

    if (hasSelector && isFullAuto == true && Input.GetKeyDown(KeyCode.B))
    {
        isFullAuto = false;
    }

    if (hasSelector && isFullAuto == false && Input.GetKeyDown(KeyCode.V))
    {
        isFullAuto = true;
    }

    if (isFullAuto == true && Input.GetKey(KeyCode.Mouse0))
    {
        Shoot();
    }

    if (isFullAuto == false && Input.GetKeyDown(KeyCode.Mouse0))
    {
        Shoot();
    }
}

void Shoot()
{
    isShooting = true;

    heat++;

    muzzleFlash.Play();
    muzzleLight.SetActive(true);

    RaycastHit hit;
    if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    {
        Debug.Log(hit.transform.name);

        Target target = hit.transform.GetComponent<Target>();
        if (target != null)
        {
            target.TakeDamage(damage);
        }
    }

    //Impact Effects
    if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range) && hit.transform.gameObject.tag == "sand")
    {
        Instantiate(sandImpactEffect, hit.point, Quaternion.LookRotation(hit.normal));

        sandImpactEffect.transform.parent = hit.transform;
    }
    
    if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range) && hit.transform.gameObject.tag == "wood")
    {
        Instantiate(woodImpactEffect, hit.point, Quaternion.LookRotation(hit.normal));

        woodImpactEffect.transform.parent = hit.transform;
    }
}

}

You have to make a reference to the woodImpactEffect then set it’s parent… Currently you are setting the reference object’s (in the script) parent… Do this instead :

if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range) && hit.transform.gameObject.tag == "wood")
 {
     GameObject WoodEffect = Instantiate(woodImpactEffect, hit.point, Quaternion.LookRotation(hit.normal));
     WoodEffect.transform.parent = hit.transform;
 }