How do i give two objects the same rotation?

Hi, i have a gun and projectile script. When i create the projectile as an isntance, i want to give it the same rotation as the gun, only it just goes at a very wierd rotation.
Here are my scripts:
using UnityEngine;
using System.Collections;

public class ShotgunScript : MonoBehaviour {
	public GameObject projectile;
	public float MoveSpeed;
	public GameObject pumphandle;
	public GameObject parent;

	void Start() {
	}

	void Update () {
		float delta = (float)0.2;
		if (Input.GetKeyDown (KeyCode.Mouse0) && !isPumping) {
			int nos = 0;
			while (nos < 10) {
				Instantiate (projectile);
				Quaternion rot = this.gameObject.transform.rotation;
				rot = new Quaternion (rot.x,rot.y,rot.z,rot.w);
				projectile.transform.rotation = rot;
				Vector3 spawnloc = new Vector3 (this.gameObject.transform.position.x, this.gameObject.transform.position.y, this.gameObject.transform.position.z);
				spawnloc = spawnloc + new Vector3 (0, 1, (float)0.1);
				projectile.transform.position = spawnloc;
				nos++;
                    }

		}
		this.gameObject.transform.position = parent.transform.position;
		Quaternion parentrot = parent.transform.rotation;
		this.gameObject.transform.rotation = parentrot;
	}
}

And the projectile:

using UnityEngine;
using System.Collections;

public class Projectile : MonoBehaviour {

	public float pathway;

	void Start () {
		float ydeviation = Random.Range ((float)-0.06, (float)0.06);
		float zdeviation = Random.Range ((float)-0.06, (float)0.06);
		Quaternion currentrot = this.gameObject.transform.rotation;
		currentrot.Set(currentrot.x,currentrot.y+ydeviation,currentrot.z+zdeviation,currentrot.w);
		this.gameObject.transform.rotation = currentrot;
	}

	void Update () {
		this.gameObject.transform.Translate (new Vector3 (0, 6, 0));
		this.pathway = this.pathway - Time.deltaTime;
		if (pathway < 0) {
			Destroy (this.gameObject);
		}
	}
}

Can anyone see what i’m doing wrong?

If I not misunderstand your question

Well when you set projectile.transform.rotation = rot;, actually you didn’t update the rotation of the object you instantiate, you only update the rotation of the game object you drag in.

To make your instantiate object have the same rotation as the gun, maybe you can just directly use the other instantiate function Institate, like this one:

Instantiate(Object original, Vector3 position, Quaternion rotation);

So how you gonna do is like this

void Update () {
         float delta = (float)0.2;
         if (Input.GetKeyDown (KeyCode.Mouse0) && !isPumping) {
             int nos = 0;
             while (nos < 10) {
                 Instantiate (projectile, trasform.position + new Vector3(.0f, 1.0f, 0.1f), transform.rotation);
               
                 nos++;
              }
 
         }
         this.gameObject.transform.position = parent.transform.position;
         Quaternion parentrot = parent.transform.rotation;
         this.gameObject.transform.rotation = parentrot;
     }

by the way, you no need to put (float)0.1 to make it as a float, you can just directly type 0.1f to make it as a float

Okay, there’s one thing bugging me when I look at all of this…

When you’re directly modifying your Quaternion to add in your xdeviation and zdeviation, do you really know what you’re doing? Messing with Quaternions isn’t easy; that’s why there are abundant functions to make it easier to manipulate an orientation.

At a glance, rather than using “currentrot.Set()”, I think you would be better off using “Quaternion.LookRotation()” and matching that to your gun’s forward vector (for example, gameObject.transform.forward). For any random variance, you can define a Vector3, give it values (with random elements), then utilize that for your LookRotation(). I believe the vector would be normalized as part of the function, but it might not hurt to ensure you’re providing exactly what you intend to provide as well.