Simple bullet script

I am trying to make a simple bullet script that will spawn in a bullet(the bullet itself will have the script that does damage), but I am getting an error.

using UnityEngine;
using System.Collections;

public class shooting : MonoBehaviour {

public float bulletSpeed = 10;



void Fire() 
{
Rigidbody bulletClone = (Rigidbody) Instantiate(bullet, transform.position, transform.rotation);
bulletClone.velocity = transform.forward * bulletSpeed;

// You can also acccess other components / scripts of the clone
//rocketClone.GetComponent<MyRocketScript>().DoSomething();
}


// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
	if (Input.GetButtonDown("Fire1"))
		Fire(); 

}

}

it is telling be that bullet does not exist in this context; there is a bullet in my prefabs, so I am not really sure what is going on.

‘bullet does not exists in the current context’, because you don’t have a ‘bullet’ variable. You need a variable to reference the prefab. Easiest way is to make a public variable so you can drag and drop the prefab onto your scripted object’s ‘shooting’ component in the inspector:

using UnityEngine; 
using System.Collections;

public class shooting : MonoBehaviour 
{
	public float bulletSpeed = 10;
	public Rigidbody bullet;
	
	
	void Fire()
	{
		Rigidbody bulletClone = (Rigidbody) Instantiate(bullet, transform.position, transform.rotation);
		bulletClone.velocity = transform.forward * bulletSpeed;
	}

	void Update () 
	{
		if (Input.GetButtonDown("Fire1"))
			Fire();
	}
}

Here is my insanely, way too complicated bullet script. But hey, it works for my game!

public float delaytoDestroy = 10;
    public float speed;
    private GameObject menu;
    public float delaydeath = 10;
    private GameObject FPS;
    private GameObject PauseManager;
    private GameObject Player;
    private GameObject PauseCamera;
    bool cursorLocked = false;
    
    //Find Inactive GameObjects
    GameObject FindInActiveObjectByName(string name)
    {
        Transform[] objs = Resources.FindObjectsOfTypeAll<Transform>() as Transform[];
        for (int i = 0; i < objs.Length; i++)
        {
            if (objs*.hideFlags == HideFlags.None)*

{
if (objs*.name == name)*
{
return objs*.gameObject;*
}
}
}
return null;
}

//Assign gameobjects to inactive current scene objects
void Start()
{
menu = FindInActiveObjectByName(“DeathMenu”);
FPS = FindInActiveObjectByName(“FPS”);
PauseManager = FindInActiveObjectByName(“PauseManager”);
Player = FindInActiveObjectByName(“Player”);
PauseCamera = FindInActiveObjectByName(“PauseCamera”);
}

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

StartCoroutine(Wait(delaytoDestroy));
IEnumerator Wait(float delay)
{

yield return new WaitForSeconds(delay);
{
Destroy(gameObject);
}
}
}

void OnTriggerEnter(Collider other)
{
//Destroy

StartCoroutine(Wait(delaytoDestroy));
IEnumerator Wait(float delay)
{

yield return new WaitForSeconds(delay);
{
Destroy(gameObject);
if (other.CompareTag(“Player”))
{
StopCoroutine(“Wait”);
}
}
}

//Death

StartCoroutine(WaitFirst(delaydeath));
IEnumerator WaitFirst(float delay)
{

yield return new WaitForSeconds(delay);
if (other.CompareTag(“Player”))
{
menu.SetActive(true);
}
}

StartCoroutine(Wait2(delaydeath));
IEnumerator Wait2(float delay)
{

yield return new WaitForSeconds(delay);
if (other.CompareTag(“Player”))
{

FPS.SetActive(false);
}
}

StartCoroutine(Wait3(delaydeath));
IEnumerator Wait3(float delay)
{

yield return new WaitForSeconds(delay);
if (other.CompareTag(“Player”))
{

PauseManager.SetActive(false);
}
}

StartCoroutine(Wait4(delaydeath));
IEnumerator Wait4(float delay)
{

yield return new WaitForSeconds(delay);
if (other.CompareTag(“Player”))
{

Player.SetActive(false);
}
}

StartCoroutine(Wait5(delaydeath));
IEnumerator Wait5(float delay)
{

yield return new WaitForSeconds(delay);
if (other.CompareTag(“Player”))
{

PauseCamera.SetActive(true);
}
}
StartCoroutine(Wait7(delaydeath));
IEnumerator Wait7(float delay)
{

yield return new WaitForSeconds(delay);
if (other.CompareTag(“Player”))
{
cursorLocked = !cursorLocked;
}
}
StartCoroutine(Wait6(delaydeath));
IEnumerator Wait6(float delay)
{

yield return new WaitForSeconds(delay);
if (other.CompareTag(“Player”))
{
if (cursorLocked)
{
Cursor.lockState = CursorLockMode.None;
Cursor.lockState = CursorLockMode.Confined;
Cursor.visible = true;
}
}
}

}

}