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?