Basic shooter script -- How do I change where the object is instantiated from?

Here is a basic shooter script that I’m using. I have attached it to a third person character, and I want to adjust the instantiation transform from where it currently is (shoots from the camera, hits character model in back of head) to the transform of a game object I have attached to the character models hand, which I tagged “ThrowingHand”.

Forgive me, I’m a noob with coding. I know there is a relatively simply way to adjust the transform, but I haven’t been able to figure out the way how. Any help is greatly appreciated!

using UnityEngine;
using System.Collections;

public class Shooter : MonoBehaviour {

    // Reference to projectile prefab to shoot
    public GameObject projectile;
    public float power = 10.0f;
   
    // Reference to AudioClip to play
    public AudioClip shootSFX;
   
    // Update is called once per frame
    void Update () {
        // Detect if fire button is pressed
        if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Jump"))
        {   
            // if projectile is specified
            if (projectile)
            {
                // Instantiante projectile at the camera + 1 meter forward with camera rotation
                GameObject newProjectile = Instantiate(projectile, transform.position + transform.forward, transform.rotation) as GameObject;

                // if the projectile does not have a rigidbody component, add one
                if (!newProjectile.GetComponent<Rigidbody>())
                {
                    newProjectile.AddComponent<Rigidbody>();
                }
                // Apply force to the newProjectile's Rigidbody component if it has one
                newProjectile.GetComponent<Rigidbody>().AddForce(transform.forward * power, ForceMode.VelocityChange);
               
                // play sound effect if set
                if (shootSFX)
                {
                    if (newProjectile.GetComponent<AudioSource> ()) { // the projectile has an AudioSource component
                        // play the sound clip through the AudioSource component on the gameobject.
                        // note: The audio will travel with the gameobject.
                        newProjectile.GetComponent<AudioSource> ().PlayOneShot (shootSFX);
                    } else {
                        // dynamically create a new gameObject with an AudioSource
                        // this automatically destroys itself once the audio is done
                        AudioSource.PlayClipAtPoint (shootSFX, newProjectile.transform.position);
                    }
                }
            }
        }
    }
}

If I understand you right…
You can parent it to a particular transform right in the instantiate call (see the docs - this is a simple Instantiate call… only 2 params… your game object, and your parent transform), or you can just change it’s parent down the road when you need to…

You’d create a reference to your gameObject (where you want it parented to) in the script, set it public… and drag your new parent game object onto the property in the property inspector…

ex.:

public GameObject myGameObject;

...

...
// somewhere in your code...
newProjectile.transform.parent  = whateverGameObject.transform;

Also works:

public transform myTransform;

...

...
// somewhere in your code...
newProjectile.transform.parent  = myTransform;

Or, the first way I described…

 newProjectile = Instantiate(projectile, myGameObject.transform);

Sorry, I glossed over that a bit, but I hope that helps!