How to Align/Orient a Bullet/Projectile along/with a Gun/Turret?

I am a beginner in Unity who is trying to make a 2D, topdown, tank-shooter game.

My question: how do I make the bullets fired from a turret in Unity actually originate from the end of its gun and continue to move in a trajectory which is parallel to the barrel of the gun?

Context: the player’s character is a tank, with a body and turret controlled by separate scripts. The turret points in the direction of the player’s cursor, represented by a crosshairs. The tank’s body is controlled independently by the keyboard.

Problem: I am trying to add another script to the turret, written some years ago by @Clet_, which takes an empty object on the end of the gun and makes it (I am assuming) the same location as an origin point for the bullet. Attempts to use this script as is result in the following error: Assets/Scripts/TurretFire.cs(30,49): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Transform, bool)’ has some invalid arguments Numerous attempts to alter the code have resulted in the same/similar errors. Clet_ mentioned in his original post that ‘Rigidbody2D’ belongs somewhere in the sample code he produced, but I am unable to determine where.

// Getting Bullets to fire in Direction of Gun Barrel - Questions & Answers - Unity Discussions
// Script by “Clet_”

using UnityEngine;

public class cannonShell : MonoBehaviour {

public float speed;
public Vector3 direction;

private void Update () {
	transform.position += direction * speed * Time.deltaTime;


public class Turret : MonoBehaviour {

public Transform TurretTip;
public GameObject cannonShellPrefab;
public AudioSource PlayerCannonSoundEffect;

private void Update () {
	if((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))) {

private void FireCannon () {
	cannonShell actualCannonShell = (cannonShell)(Instantiate (cannonShellPrefab, TurretTip, Quaternion.identity) as GameObject);
	actualCannonShell.direction = TurretTip.forward;


I should clarify that the first line of the method/constructor “FireCannon()” is the source of the error.

You can assign the transform.forward of the gun/turret to the velocity of the bullet, multiplied by some factor that represents the actual speed of the bullet.