Why can't I make my gun work for a fps?

Hi guys,
Basically I’m new to unity and scripting and for my college I’m making a fps level. I have put a First Person Controller into my scene and I have made a model gun as well.

I have looked at about a million tutorials, example and what not but I cant seem to make it work. I think it is something the do with the way I’m scripting prefabs or something.

Can someone please help understand this and explain where I’m going wrong

Thanks everyone, really appreciate the help

I’m just trying to make the bullet come out from the end of a gun.
This is the script that I found from this forum:

var BulletPrefab : GameObject;

function Update() { if(Input.GetButton(“Fire1”) {

bullet = Instantiate(BulletPrefab; gameObject.Find("Spawn").transform.position;                                    Quaternion.identity)
bullet.rigidbody.AddForce(transform.forward * Speed);


This is how they said to use it:

"Copy this script to your gun. create an empty gameobject, rename it to “Spawn” and place it in front of your gun. create your bullet and make it a prefab add a rigidbody to it drag this prefab to your script in the gun and place it in BulletPrefab set your speed When you click the left mouse button, the bullet should move forward in the speed you have set

none of this belongs to me.The credit goes to the tornado twins.i saw this video on youtube"

Thanks Guys!

Attach an empty game object to the end of you gun, where the bullet spawns. Make a bullet prefab.

Here is a simple script to fire a bullet using a rigid body I made (comments explain code)(Also, I didn’t test it):

public var bullet : Transform; //The bullet to be spawned

//Attached to bullet spawn point
function Update()
if(Input.GetButtonDown("Fire1")) //When you press fire, make a bullet

This is what you attach to the bullet for movement:

@script RequireComponent(Rigidbody) //Make sure bullet has rigidbody attached

public var bulletSpeed : float = 25; //bullet's speed
public var bullet : Transform;
public var gun : Transform;
public var range : float = 500; // range of bullet

function Update(){
rigidbody.AddRelativeForce(Vector3.forward * bulletSpeed);
if(Vector3.distance(transform.position, gun.position) >= range) {Destroy(bullet);} //if it misses, destroy itself

function OnCollisionEnter(){
Destroy(bullet); //When it hits, destroy itself

Hope this helped you understand.

Is it mandatory that an actual bullet comes out of the gun? Or could you just simulate it with a RayCast?

var range = 100.0;
var force = 10.0;
var damage = 15.0;
//Initialise effects
private var hitParticles : ParticleEmitter;

//Initialise bullet spark off
function Start()
	hitParticles = GetComponentInChildren(ParticleEmitter);
		hitParticles.emit = false;
		bulletsLeft = bulletsPerClip;

//Script for firing		
function FireOneShot()
	var direction = transform.TransformDirection(Vector3.forward);
	var hit : RaycastHit;	
	//Test for hit
	if(Physics.Raycast(transform.position, direction, hit, range))
		//Apply force to any hit objects
			hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
		//Move particle system and spawn particles
			hitParticles.transform.position = hit.point;
			hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
		//Send damage to hit object
		hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
	//Take 1 from the remaing bullets
	//Register that the player shot this frame for muzzle effects
	m_LastFrameShot = Time.frameCount;
	enabled = true;
	//Reload if you run out of ammo

When applied to an object this should apply a force to any rigid body it hits and emit the particles attached to the object (e.g. sparks)

im having the same issue with my script ive done the code and itembuilding right i just dont know how to make them work together