Hi so i have a spawn script for a bullet. And. When it spawns, it doesnt spawn with the same rotation as the object the it spawns from.
Could some tell me what to do?
Heres my code
using UnityEngine;
using System.Collections;
public class SpawnProjectile : MonoBehaviour {
public GameObject projectile;
public float ROF = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0) & ROF >= 10.0f) {
Instantiate (projectile, transform.position, Quaternion.identity);
ROF = 0.0f;
}
if (ROF < 10.0f) {
ROF += 0.1f;
}
}
That is because Quaternion.identity is a pre-made Quaternion witn no rotation (0,0,0). I would assume you can see when you execute that the projectile has this rotation.
You already did the right thing by using transform.position when Instantiating projectile.
You want to pass transform.rotation from the parent object you mention. Assuming this MonoBehaviour is attached to it you can get that my referencing ether transform.rotation, this.transform.rotation or GetComponent<Transform>().rotation.
Excuse me if there are errors in this, i haven’t used Unity for a little while.